Esempio n. 1
0
        /// <summary>
        /// 識別子を読み終えた状態からの解析
        /// </summary>
        /// <param name="st"></param>
        /// <returns></returns>
        public static VariableTerm ReduceVariable(VariableToken id, WordCollection wc)
        {
            IOperandTerm operand = null;
            IOperandTerm op1 = null;
            IOperandTerm op2 = null;
            IOperandTerm op3 = null;
            int i = 0;
            while (true)
            {
                if (wc.Current.Type != ':')
                    break;
                if (i >= 3)
                    throw new CodeEE(id.Code.ToString() + "の引数が多すぎます");
                wc.ShiftNext();

                operand = ExpressionParser.ReduceVariableArgument(wc, id.Code);
                if (i == 0)
                    op1 = operand;
                else if (i == 1)
                    op2 = operand;
                else if (i == 2)
                    op3 = operand;
                i++;
            }
            return ReduceVariable(id, op1, op2, op3);
        }
Esempio n. 2
0
 public FixedVariableTerm(VariableToken token)
     : base(token)
 {
     this.Identifier = token;
     transporter = new Int64[3];
     allArgIsConst = true;
 }
Esempio n. 3
0
 public FixedVariableTerm(VariableToken token, Int64[] args)
     : base(token)
 {
     allArgIsConst = true;
     this.Identifier = token;
     transporter = new Int64[3];
     for(int i = 0;i< args.Length;i++)
         transporter[i] = args[i];
 }
Esempio n. 4
0
 protected VariableTerm(VariableToken token)
     : base(token.VariableType)
 {
 }
Esempio n. 5
0
        public VariableTerm(VariableToken token, IOperandTerm[] args)
            : base(token.VariableType)
        {
            this.Identifier = token;
            arguments = args;
            transporter = new Int64[arguments.Length];

            allArgIsConst = false;
            for (int i = 0; i < arguments.Length; i++)
            {
                if (!(arguments[i] is SingleTerm))
                    return;
                transporter[i] = ((SingleTerm)arguments[i]).Int;
            }
            allArgIsConst = true;
        }
Esempio n. 6
0
 public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
 {
     IOperandTerm[] terms = popTerms(line);
     if (!checkArgumentType(line, exm, terms))
         return null;
     VariableToken[] vars = new VariableToken[2] { null, null };
     if (terms[0] is SingleTerm)
     {
         if ((vars[0] = GlobalStatic.IdentifierDictionary.GetVariableToken(((SingleTerm)terms[0]).Str, null, true)) == null)
         {
             warn("ARRAYCOPY命令の第1引数\"" + ((SingleTerm)terms[0]).Str + "\"は変数名として存在しません", line, 2, false);
             return null;
         }
         if (!vars[0].IsArray1D && !vars[0].IsArray2D && !vars[0].IsArray3D)
         {
             warn("ARRAYCOPY命令の第1引数\"" + ((SingleTerm)terms[0]).Str + "\"は配列変数ではありません", line, 2, false);
             return null;
         }
         if (vars[0].IsCharacterData)
         {
             warn("ARRAYCOPY命令の第1引数\"" + ((SingleTerm)terms[0]).Str + "\"はキャラクタ変数です(対応していません)", line, 2, false);
             return null;
         }
     }
     if (terms[1] is SingleTerm)
     {
         if ((vars[1] = GlobalStatic.IdentifierDictionary.GetVariableToken(((SingleTerm)terms[1]).Str, null, true)) == null)
         {
             warn("ARRAYCOPY命令の第2引数\"" + ((SingleTerm)terms[1]).Str + "\"は変数名として存在しません", line, 2, false);
             return null;
         }
         if (!vars[1].IsArray1D && !vars[1].IsArray2D && !vars[1].IsArray3D)
         {
             warn("ARRAYCOPY命令の第2引数\"" + ((SingleTerm)terms[1]).Str + "\"は配列変数ではありません", line, 2, false);
         }
         if (vars[1].IsCharacterData)
         {
             warn("ARRAYCOPY命令の第2引数\"" + ((SingleTerm)terms[1]).Str + "\"はキャラクタ変数です(対応していません)", line, 2, false);
             return null;
         }
         if (vars[1].Readonly)
         {
             warn("ARRAYCOPY命令の第2引数\"" + ((SingleTerm)terms[1]).Str + "\"は値を変更できない変数です", line, 2, false);
             return null;
         }
     }
     if ((vars[0] != null) && (vars[1] != null))
     {
         if ((vars[0].IsArray1D && !vars[1].IsArray1D) || (vars[0].IsArray2D && !vars[1].IsArray2D) || (vars[0].IsArray3D && !vars[1].IsArray3D))
         {
             warn("ARRAYCOPY命令の2つの引数の次元が異なります", line, 2, false);
             return null;
         }
     }
     return new SpCopyArrayArgument(terms[0], terms[1]);
 }
Esempio n. 7
0
 public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
 {
     IOperandTerm[] terms = popTerms(line);
     if (!checkArgumentType(line, exm, terms))
         return null;
     List<VariableToken> varTokens = new List<VariableToken>();
     for (int i = 2; i < terms.Length; i++)
     {
         if (terms[i] == null)
         { warn("第" + (i + 1) + "引数を省略できません", line, 2, false); return null; }
         VariableTerm vTerm = getChangeableVariable(terms, i + 1, line);
         if (vTerm == null)
             return null;
         VariableToken vToken = vTerm.Identifier;
         if (vToken.IsCharacterData)
         { warn("キャラクタ変数"+ vToken.Name+"はセーブできません(キャラクタ変数のSAVEにはSAVECHARAを使用します)", line, 2, false); return null; }
         if (vToken.IsPrivate)
         { warn("プライベート変数" + vToken.Name + "はセーブできません", line, 2, false); return null; }
         if (vToken.IsLocal)
         { warn("ローカル変数" + vToken.Name + "はセーブできません", line, 2, false); return null; }
         if (vToken.Readonly)
         { warn("定数はセーブできません", line, 2, false); return null; }
         if (vToken.IsCalc)
         { warn("疑似変数はセーブできません", line, 2, false); return null; }
         if (vToken.IsReference)
         { warn("参照型変数はセーブできません", line, 2, false); return null; }
         varTokens.Add(vToken);
     }
     for (int i = 0; i < varTokens.Count; i++)
     {
         for (int j = i + 1; j < varTokens.Count; j++)
             if (varTokens[i] == varTokens[j])
             {
                 warn("変数" + varTokens[i].Name + "を二度以上保存しようとしています", line, 1, false);
                 return null;
             }
     }
     VariableToken[] arg3 = new VariableToken[varTokens.Count];
     varTokens.CopyTo(arg3);
     return new SpSaveVarArgument(terms[0], terms[1], arg3);
 }
Esempio n. 8
0
 public SpSplitArgument(IOperandTerm s1, IOperandTerm s2, VariableToken varId, VariableTerm num)
 {
     TargetStr = s1;
     Split = s2;
     Var = varId;
     Num = num;
 }
        void doNormalFunction(InstructionLine func)
        {
            Int64 iValue = 0;
            string str = null;
            IOperandTerm term = null;
            switch (func.FunctionCode)
            {

                case FunctionCode.PRINTBUTTON://変数の内容
                    {
                        if (skipPrint)
                            break;
                        SpButtonArgument bArg = (SpButtonArgument)func.Argument;
                        str = bArg.PrintStrTerm.GetStrValue(exm);
                        //ボタン処理に絡んで表示がおかしくなるため、PRINTBUTTONでの改行コードはオミット
                        str = str.Replace("\n", "");
                        if (bArg.ButtonWord.GetOperandType() == typeof(long))
                            exm.Console.PrintButton(str,  bArg.ButtonWord.GetIntValue(exm));
                        else
                            exm.Console.PrintButton(str, bArg.ButtonWord.GetStrValue(exm));
                    }
                    break;
                case FunctionCode.PRINTBUTTONC://変数の内容
                case FunctionCode.PRINTBUTTONLC:
                    {
                        if (skipPrint)
                            break;
                        SpButtonArgument bArg = (SpButtonArgument)func.Argument;
                        str = bArg.PrintStrTerm.GetStrValue(exm);
                        //ボタン処理に絡んで表示がおかしくなるため、PRINTBUTTONでの改行コードはオミット
                        str = str.Replace("\n", "");
                        bool isRight = (func.FunctionCode == FunctionCode.PRINTBUTTONC) ? true : false;
                        if (bArg.ButtonWord.GetOperandType() == typeof(long))
                            exm.Console.PrintButtonC(str, bArg.ButtonWord.GetIntValue(exm), isRight);
                        else
                            exm.Console.PrintButtonC(str, bArg.ButtonWord.GetStrValue(exm), isRight);
                    }
                    break;
                case FunctionCode.PRINTPLAIN:
                case FunctionCode.PRINTPLAINFORM:
                    {
                        if (skipPrint)
                            break;
                        term = ((ExpressionArgument)func.Argument).Term;
                        exm.Console.PrintPlain(term.GetStrValue(exm));
                    }
                    break;
                case FunctionCode.DRAWLINE://画面の左端から右端まで----と線を引く。
                    if (skipPrint)
                        break;
                    exm.Console.PrintBar();
                    exm.Console.NewLine();
                    break;
                case FunctionCode.CUSTOMDRAWLINE:
                case FunctionCode.DRAWLINEFORM:
                    {
                        if (skipPrint)
                            break;
                        term = ((ExpressionArgument)func.Argument).Term;
                        str = term.GetStrValue(exm);
                        exm.Console.printCustomBar(str);
                        //exm.Console.setStBar(str);
                        //exm.Console.PrintBar();
                        exm.Console.NewLine();
                        //exm.Console.setStBar(Config.DrawLineString);
                    }
                    break;
                case FunctionCode.PRINT_ABL://能力。引数は登録番号
                case FunctionCode.PRINT_TALENT://素質
                case FunctionCode.PRINT_MARK://刻印
                case FunctionCode.PRINT_EXP://経験
                    {
                        if (skipPrint)
                            break;
                        ExpressionArgument intExpArg = (ExpressionArgument)func.Argument;
                        Int64 target = intExpArg.Term.GetIntValue(exm);
                        exm.Console.Print(vEvaluator.GetCharacterDataString(target, func.FunctionCode));
                        exm.Console.NewLine();
                    }
                    break;
                case FunctionCode.PRINT_PALAM://パラメータ
                    {
                        if (skipPrint)
                            break;
                        ExpressionArgument intExpArg = (ExpressionArgument)func.Argument;
                        Int64 target = intExpArg.Term.GetIntValue(exm);
                        int count = 0;
                        ///100以降は否定の珠とかなので表示しない
                        for (int i = 0; i < 100; i++)
                        {
                            string printStr = vEvaluator.GetCharacterParamString(target, i);
                            if (printStr != null)
                            {
                                exm.Console.PrintC(printStr, true);
                                count++;
                                if ((Config.PrintCPerLine > 0) && (count % Config.PrintCPerLine == 0))
                                    exm.Console.PrintFlush(false);
                            }
                        }
                        exm.Console.PrintFlush(false);
                    }
                    break;
                case FunctionCode.PRINT_ITEM://所持アイテム
                    if (skipPrint)
                        break;
                    exm.Console.Print(vEvaluator.GetHavingItemsString());
                    exm.Console.NewLine();
                    break;
                case FunctionCode.PRINT_SHOPITEM://ショップで売っているアイテム
                    {
                        if (skipPrint)
                            break;
                        int length = Math.Min(vEvaluator.ITEMSALES.Length, vEvaluator.ITEMNAME.Length);
                        int count = 0;
                        for (int i = 0; i < length; i++)
                        {
                            if (vEvaluator.ItemSales(i))
                            {
                                string printStr = vEvaluator.ITEMNAME[i];
                                if (printStr == null)
                                    printStr = "";
                                Int64 price = vEvaluator.ITEMPRICE[i];
                                // 1.52a改変部分 (単位の差し替えおよび前置、後置に対応)
                                if (Config.MoneyFirst)
                                    exm.Console.PrintC(string.Format("[{2}] {0}({3}{1})", printStr, price, i, Config.MoneyLabel), false);
                                else
                                    exm.Console.PrintC(string.Format("[{2}] {0}({1}{3})", printStr, price, i, Config.MoneyLabel), false);
                                count++;
                                if ((Config.PrintCPerLine > 0) && (count % Config.PrintCPerLine == 0))
                                    exm.Console.PrintFlush(false);
                            }
                        }
                        exm.Console.PrintFlush(false);
                    }
                    break;
                case FunctionCode.UPCHECK://パラメータの変動
                    vEvaluator.UpdateInUpcheck(exm.Console, skipPrint);
                    break;
                case FunctionCode.CUPCHECK://パラメータの変動(任意キャラ版)
                    {
                        ExpressionArgument intExpArg = (ExpressionArgument)func.Argument;
                        Int64 target = intExpArg.Term.GetIntValue(exm);
                        vEvaluator.CUpdateInUpcheck(exm.Console, target, skipPrint);
                    }
                    break;
                case FunctionCode.DELALLCHARA:
                    {
                        vEvaluator.DelAllCharacter();
                        break;
                    }
                case FunctionCode.PICKUPCHARA:
                    {
                        ExpressionArrayArgument intExpArg = (ExpressionArrayArgument)func.Argument;
                        Int64[] NoList = new Int64[intExpArg.TermList.Length];
                        Int64 charaNum = vEvaluator.CHARANUM;
                        for (int i = 0; i < intExpArg.TermList.Length; i++)
                        {
                            IOperandTerm term_i = intExpArg.TermList[i];
                            NoList[i] = term_i.GetIntValue(exm);
                            if (!(term_i is VariableTerm) || ((((VariableTerm)term_i).Identifier.Code != VariableCode.MASTER) && (((VariableTerm)term_i).Identifier.Code != VariableCode.ASSI) && (((VariableTerm)term_i).Identifier.Code != VariableCode.TARGET)))
                            if (NoList[i] < 0 || NoList[i] >= charaNum)
                                throw new CodeEE("命令PICKUPCHARAの第" + (i + 1).ToString() + "引数にキャラリストの範囲外の値(" + NoList[i].ToString() + ")が与えられました");
                        }
                        vEvaluator.PickUpChara(NoList);
                    }
                    break;
                case FunctionCode.ADDDEFCHARA:
                    {
                        //デバッグコマンドなら通す
                        if ((func.ParentLabelLine != null) && (func.ParentLabelLine.LabelName != "SYSTEM_TITLE"))
                            throw new CodeEE("@SYSTEM_TITLE以外でこの命令を使うことはできません");
                        vEvaluator.AddCharacterFromCsvNo(0);
                        if (GlobalStatic.GameBaseData.DefaultCharacter > 0)
                            vEvaluator.AddCharacterFromCsvNo(GlobalStatic.GameBaseData.DefaultCharacter);
                        break;
                    }
                case FunctionCode.PUTFORM://@SAVEINFO関数でのみ使用可能。PRINTFORMと同様の書式でセーブデータに概要をつける。
                    {
                        term = ((ExpressionArgument)func.Argument).Term;
                        str = term.GetStrValue(exm);
                        if (vEvaluator.SAVEDATA_TEXT != null)
                            vEvaluator.SAVEDATA_TEXT += str;
                        else
                            vEvaluator.SAVEDATA_TEXT = str;
                        break;
                    }
                case FunctionCode.QUIT://ゲームを終了
                    exm.Console.Quit();
                    break;

                case FunctionCode.VARSIZE:
                    {
                        SpVarsizeArgument versizeArg = (SpVarsizeArgument)func.Argument;
                        VariableToken varID = versizeArg.VariableID;
                        vEvaluator.VarSize(varID);
                    }
                    break;
                case FunctionCode.SAVEDATA:
                    {
                        SpSaveDataArgument spSavedataArg = (SpSaveDataArgument)func.Argument;
                        Int64 target = spSavedataArg.Target.GetIntValue(exm);
                        if (target < 0)
                            throw new CodeEE("SAVEDATAの引数に負の値(" + target.ToString() + ")が指定されました");
                        else if (target > int.MaxValue)
                            throw new CodeEE("SAVEDATAの引数(" + target.ToString() + ")が大きすぎます");
                        string savemes = spSavedataArg.StrExpression.GetStrValue(exm);
                        if (savemes.Contains("\n"))
                            throw new CodeEE("SAVEDATAのセーブテキストに改行文字が与えられました(セーブデータが破損するため改行文字は使えません)");
                        if (!vEvaluator.SaveTo((int)target, savemes))
                        {
                            console.PrintError("SAVEDATA命令によるセーブ中に予期しないエラーが発生しました");
                        }
                    }
                    break;

                case FunctionCode.POWER:
                    {
                        SpPowerArgument powerArg = (SpPowerArgument)func.Argument;
                        double x = powerArg.X.GetIntValue(exm);
                        double y = powerArg.Y.GetIntValue(exm);
                        double pow = Math.Pow(x, y);
                        if (double.IsNaN(pow))
                            throw new CodeEE("累乗結果が非数値です");
                        else if (double.IsInfinity(pow))
                            throw new CodeEE("累乗結果が無限大です");
                        else if ((pow >= Int64.MaxValue) || (pow <= Int64.MinValue))
                            throw new CodeEE("累乗結果(" + pow.ToString() + ")が64ビット符号付き整数の範囲外です");
                        powerArg.VariableDest.SetValue((long)pow, exm);
                        break;
                    }
                case FunctionCode.SWAP:
                    {
                        SpSwapVarArgument arg = (SpSwapVarArgument)func.Argument;
                        //1756beta2+v11
                        //値を読み出す前に添え字を確定させておかないと、RANDが添え字にある場合正しく処理できない
                        FixedVariableTerm vTerm1 = arg.var1.GetFixedVariableTerm(exm);
                        FixedVariableTerm vTerm2 = arg.var2.GetFixedVariableTerm(exm);
                        if (vTerm1.GetOperandType() != vTerm2.GetOperandType())
                            throw new CodeEE("入れ替える変数の型が異なります");
                        if (vTerm1.GetOperandType() == typeof(Int64))
                        {
                            Int64 temp = vTerm1.GetIntValue(exm);
                            vTerm1.SetValue(vTerm2.GetIntValue(exm), exm);
                            vTerm2.SetValue(temp, exm);
                        }
                        else if (arg.var1.GetOperandType() == typeof(string))
                        {
                            string temps = vTerm1.GetStrValue(exm);
                            vTerm1.SetValue(vTerm2.GetStrValue(exm), exm);
                            vTerm2.SetValue(temps, exm);
                        }
                        else
                        {
                            throw new CodeEE("不明な変数型です");
                        }
                        break;
                    }
                case FunctionCode.GETTIME:
                    {
                        long date = DateTime.Now.Year;
                        date = date * 100 + DateTime.Now.Month;
                        date = date * 100 + DateTime.Now.Day;
                        date = date * 100 + DateTime.Now.Hour;
                        date = date * 100 + DateTime.Now.Minute;
                        date = date * 100 + DateTime.Now.Second;
                        date = date * 1000 + DateTime.Now.Millisecond;
                        vEvaluator.RESULT = date;//17桁。2京くらい。
                        vEvaluator.RESULTS = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                    }
                    break;
                case FunctionCode.SETCOLOR:
                    {
                        SpColorArgument colorArg = (SpColorArgument)func.Argument;
                        Int64 colorR;
                        Int64 colorG;
                        Int64 colorB;
                        if (colorArg.RGB != null)
                        {
                            Int64 colorRGB = colorArg.RGB.GetIntValue(exm);
                            colorR = (colorRGB & 0xFF0000) >> 16;
                            colorG = (colorRGB & 0x00FF00) >> 8;
                            colorB = (colorRGB & 0x0000FF);
                        }
                        else
                        {
                            colorR = colorArg.R.GetIntValue(exm);
                            colorG = colorArg.G.GetIntValue(exm);
                            colorB = colorArg.B.GetIntValue(exm);
                            if ((colorR < 0) || (colorG < 0) || (colorB < 0))
                                throw new CodeEE("SETCOLORの引数に0未満の値が指定されました");
                            if ((colorR > 255) || (colorG > 255) || (colorB > 255))
                                throw new CodeEE("SETCOLORの引数に255を超える値が指定されました");
                        }
                        Color c = Color.FromArgb((Int32)colorR, (Int32)colorG, (Int32)colorB);
                        exm.Console.SetStringStyle(c);
                    }
                    break;
                case FunctionCode.SETCOLORBYNAME:
                    {
                        string colorName = func.Argument.ConstStr;
                        Color c = Color.FromName(colorName);
                        if (colorName != "BLACK" && (c.R == 0 && c.G == 0 && c.B == 0))
                            throw new CodeEE("指定された色名\"" + colorName + "\"は無効な色名です");
                        exm.Console.SetStringStyle(c);
                    }
                    break;
                case FunctionCode.SETBGCOLOR:
                    {
                        SpColorArgument colorArg = (SpColorArgument)func.Argument;
                        Int64 colorR;
                        Int64 colorG;
                        Int64 colorB;
                        if (colorArg.IsConst)
                        {
                            Int64 colorRGB = colorArg.ConstInt;
                            colorR = (colorRGB & 0xFF0000) >> 16;
                            colorG = (colorRGB & 0x00FF00) >> 8;
                            colorB = (colorRGB & 0x0000FF);
                        }
                        else if (colorArg.RGB != null)
                        {
                            Int64 colorRGB = colorArg.RGB.GetIntValue(exm);
                            colorR = (colorRGB & 0xFF0000) >> 16;
                            colorG = (colorRGB & 0x00FF00) >> 8;
                            colorB = (colorRGB & 0x0000FF);
                        }
                        else
                        {
                            colorR = colorArg.R.GetIntValue(exm);
                            colorG = colorArg.G.GetIntValue(exm);
                            colorB = colorArg.B.GetIntValue(exm);
                            if ((colorR < 0) || (colorG < 0) || (colorB < 0))
                                throw new CodeEE("SETCOLORの引数に0未満の値が指定されました");
                            if ((colorR > 255) || (colorG > 255) || (colorB > 255))
                                throw new CodeEE("SETCOLORの引数に255を超える値が指定されました");
                        }
                        Color c = Color.FromArgb((Int32)colorR, (Int32)colorG, (Int32)colorB);
                        exm.Console.SetBgColor(c);
                    }
                    break;
                case FunctionCode.SETBGCOLORBYNAME:
                    {
                        string colorName = func.Argument.ConstStr;
                        Color c = Color.FromName(colorName);
                        if (colorName != "BLACK" && (c.R == 0 && c.G == 0 && c.B == 0))
                            throw new CodeEE("指定された色名\"" + colorName + "\"は無効な色名です");
                        exm.Console.SetBgColor(c);
                    }
                    break;
                case FunctionCode.FONTSTYLE:
                    {
                        FontStyle fs = FontStyle.Regular;
                        if (func.Argument.IsConst)
                            iValue = func.Argument.ConstInt;
                        else
                            iValue = ((ExpressionArgument)func.Argument).Term.GetIntValue(exm);
                        if ((iValue & 1) != 0)
                            fs |= FontStyle.Bold;
                        if ((iValue & 2) != 0)
                            fs |= FontStyle.Italic;
                        if ((iValue & 4) != 0)
                            fs |= FontStyle.Strikeout;
                        if ((iValue & 8) != 0)
                            fs |= FontStyle.Underline;
                        exm.Console.SetStringStyle(fs);
                    }
                    break;
                case FunctionCode.SETFONT:
                    if (func.Argument.IsConst)
                        str = func.Argument.ConstStr;
                    else
                        str = ((ExpressionArgument)func.Argument).Term.GetStrValue(exm);
                    exm.Console.SetFont(str);
                    break;
                case FunctionCode.ALIGNMENT:
                    str = func.Argument.ConstStr;
                    if (str.Equals("LEFT", Config.SCVariable))
                        exm.Console.Alignment = DisplayLineAlignment.LEFT;
                    else if (str.Equals("CENTER", Config.SCVariable))
                        exm.Console.Alignment = DisplayLineAlignment.CENTER;
                    else if (str.Equals("RIGHT", Config.SCVariable))
                        exm.Console.Alignment = DisplayLineAlignment.RIGHT;
                    else
                        throw new CodeEE("ALIGNMENTのキーワード\"" + str + "\"は未定義です");
                    break;

                case FunctionCode.REDRAW:
                    if(func.Argument.IsConst)
                        iValue = func.Argument.ConstInt;
                    else
                        iValue = ((ExpressionArgument)func.Argument).Term.GetIntValue(exm);
                    exm.Console.SetRedraw(iValue);
                    break;

                case FunctionCode.RESET_STAIN:
                    {
                        if (func.Argument.IsConst)
                            iValue = func.Argument.ConstInt;
                        else
                            iValue = ((ExpressionArgument)func.Argument).Term.GetIntValue(exm);
                        vEvaluator.SetDefaultStain(iValue);
                    }
                    break;
                case FunctionCode.SPLIT:
                    {
                        SpSplitArgument spSplitArg = (SpSplitArgument)func.Argument;
                        string target = spSplitArg.TargetStr.GetStrValue(exm);
                        string[] split = new string[] { spSplitArg.Split.GetStrValue(exm) };
                        string[] retStr = target.Split(split, StringSplitOptions.None);
                        spSplitArg.Var.SetValue(retStr, new long[] { 0, 0, 0 });
                        spSplitArg.Num.SetValue(retStr.Length, exm);
                    }
                    break;
                case FunctionCode.PRINTCPERLINE:
                    {
                        SpGetIntArgument spGetintArg = (SpGetIntArgument)func.Argument;
                        spGetintArg.VarToken.SetValue((Int64)Config.PrintCPerLine, exm);
                    }
                    break;
                case FunctionCode.SAVENOS:
                    {
                        SpGetIntArgument spGetintArg = (SpGetIntArgument)func.Argument;
                        spGetintArg.VarToken.SetValue((Int64)Config.SaveDataNos, exm);
                    }
                    break;
                case FunctionCode.FORCEKANA:
                    if (func.Argument.IsConst)
                        iValue = func.Argument.ConstInt;
                    else
                        iValue = ((ExpressionArgument)func.Argument).Term.GetIntValue(exm);
                    exm.ForceKana(iValue);
                    break;
                case FunctionCode.SKIPDISP:
                    {
                        iValue = (func.Argument.IsConst) ? func.Argument.ConstInt : ((ExpressionArgument)func.Argument).Term.GetIntValue(exm);
                        skipPrint = (iValue != 0);
                        userDefinedSkip = (iValue != 0);
                        vEvaluator.RESULT = (skipPrint) ? 1L : 0L;
                    }
                    break;
                case FunctionCode.NOSKIP:
                    {
                        if (func.JumpTo == null)
                            throw new CodeEE("対応するENDNOSKIPのないNOSKIPです");
                        saveSkip = skipPrint;
                        if (skipPrint)
                            skipPrint = false;
                    }
                    break;
                case FunctionCode.ENDNOSKIP:
                    {
                        if (func.JumpTo == null)
                            throw new CodeEE("対応するNOSKIPのないENDNOSKIPです");
                        if (saveSkip)
                            skipPrint = true;
                    }
                    break;
                case FunctionCode.OUTPUTLOG:
                    exm.Console.outputLog(null);
                    break;
                case FunctionCode.ARRAYSHIFT: //配列要素をずらす
                    {
                        SpArrayShiftArgument arrayArg = (SpArrayShiftArgument)func.Argument;
                        if (!arrayArg.VarToken.Identifier.IsArray1D)
                            throw new CodeEE("ARRAYSHIFTは1次元配列および配列型キャラクタ変数のみに対応しています");
                        FixedVariableTerm dest = arrayArg.VarToken.GetFixedVariableTerm(exm);
                        int shift = (int)arrayArg.Num1.GetIntValue(exm);
                        if (shift == 0)
                            break;
                        int start = (int)arrayArg.Num3.GetIntValue(exm);
                        if (start <  0)
                            throw new CodeEE("ARRAYSHIFTの第4引数が負の値(" + start.ToString() + ")です");
                        int num;
                        if (arrayArg.Num4 != null)
                        {
                            num = (int)arrayArg.Num4.GetIntValue(exm);
                            if (num < 0)
                                throw new CodeEE("ARRAYSHIFTの第5引数が負の値(" + start.ToString() + ")です");
                            if (num == 0)
                                break;
                        }
                        else
                            num = -1;
                        if (dest.Identifier.IsInteger)
                        {
                            Int64 def = arrayArg.Num2.GetIntValue(exm);
                            vEvaluator.ShiftArray(dest, shift, def, start, num);
                        }
                        else
                        {
                            string defs = arrayArg.Num2.GetStrValue(exm);
                            vEvaluator.ShiftArray(dest, shift, defs, start, num);
                        }
                        break;
                    }
                case FunctionCode.ARRAYREMOVE:
                    {
                        SpArrayControlArgument arrayArg = (SpArrayControlArgument)func.Argument;
                        if (!arrayArg.VarToken.Identifier.IsArray1D)
                            throw new CodeEE("ARRAYREMOVEは1次元配列および配列型キャラクタ変数のみに対応しています");
                        FixedVariableTerm p = arrayArg.VarToken.GetFixedVariableTerm(exm);
                        int start = (int)arrayArg.Num1.GetIntValue(exm);
                        int num = (int)arrayArg.Num2.GetIntValue(exm);
                        if (start < 0)
                            throw new CodeEE("ARRAYREMOVEの第2引数が負の値(" + start.ToString() + ")です");
                        if (num < 0)
                            throw new CodeEE("ARRAYREMOVEの第3引数が負の値(" + start.ToString() + ")です");
                        if (num == 0)
                            break;
                        vEvaluator.RemoveArray(p, start, num);
                        break;
                    }
                case FunctionCode.ARRAYSORT:
                    {
                        SpArraySortArgument arrayArg = (SpArraySortArgument)func.Argument;
                        if (!arrayArg.VarToken.Identifier.IsArray1D)
                            throw new CodeEE("ARRAYRESORTは1次元配列および配列型キャラクタ変数のみに対応しています");
                        FixedVariableTerm p = arrayArg.VarToken.GetFixedVariableTerm(exm);
                        int start = (int)arrayArg.Num1.GetIntValue(exm);
                        if (start < 0)
                            throw new CodeEE("ARRAYSORTの第3引数が負の値(" + start.ToString() + ")です");
                        int num = 0;
                        if (arrayArg.Num2 != null)
                        {
                            num = (int)arrayArg.Num2.GetIntValue(exm);
                            if (num < 0)
                                throw new CodeEE("ARRAYSORTの第4引数が負の値(" + start.ToString() + ")です");
                            if (num == 0)
                                break;
                        }
                        else
                            num = -1;
                        vEvaluator.SortArray(p, arrayArg.Order, start, num);
                        break;
                    }
                case FunctionCode.ARRAYCOPY:
                    {
                        SpCopyArrayArgument arrayArg = (SpCopyArrayArgument)func.Argument;
                        IOperandTerm varName1 = arrayArg.VarName1;
                        IOperandTerm varName2 = arrayArg.VarName2;
                        VariableToken[] vars = new VariableToken[2] { null, null };
                        if (!(varName1 is SingleTerm) || (varName2 is SingleTerm))
                        {
                            string[] names = new string[2] { null, null };
                            names[0] = varName1.GetStrValue(exm);
                            names[1] = varName2.GetStrValue(exm);
                            if ((vars[0] = GlobalStatic.IdentifierDictionary.GetVariableToken(names[0], null, true)) == null)
                                throw new CodeEE("ARRAYCOPY命令の第1引数(" + names[0] + ")が有効な変数名ではありません");
                            if (!vars[0].IsArray1D && !vars[0].IsArray2D && !vars[0].IsArray3D)
                                throw new CodeEE("ARRAYCOPY命令の第1引数\"" + names[0] + "\"は配列変数ではありません");
                            if (vars[0].IsCharacterData)
                                throw new CodeEE("ARRAYCOPY命令の第1引数\"" + names[0] + "\"はキャラクタ変数です(対応していません)");
                            if ((vars[1] = GlobalStatic.IdentifierDictionary.GetVariableToken(names[1], null, true)) == null)
                                throw new CodeEE("ARRAYCOPY命令の第2引数(" + names[0] + ")が有効な変数名ではありません");
                            if (!vars[1].IsArray1D && !vars[1].IsArray2D && !vars[1].IsArray3D)
                                throw new CodeEE("ARRAYCOPY命令の第1引数\"" + names[1] + "\"は配列変数ではありません");
                            if (vars[1].IsCharacterData)
                                throw new CodeEE("ARRAYCOPY命令の第2引数\"" + names[1] + "\"はキャラクタ変数です(対応していません)");
                            if (vars[1].Readonly)
                                throw new CodeEE("ARRAYCOPY命令の第2引数\"" + names[1] + "\"は値を変更できない変数です");
                            if ((vars[0].IsArray1D && !vars[1].IsArray1D) || (vars[0].IsArray2D && !vars[1].IsArray2D) || (vars[0].IsArray3D && !vars[1].IsArray3D))
                                throw new CodeEE("ARRAYCOPY命令の2つの配列変数の次元数が一致していません");
                        }
                        else
                        {
                            vars[0] = GlobalStatic.IdentifierDictionary.GetVariableToken(((SingleTerm)varName1).Str, null, true);
                            vars[1] = GlobalStatic.IdentifierDictionary.GetVariableToken(((SingleTerm)varName2).Str, null, true);
                        }
                        vEvaluator.CopyArray(vars[0], vars[1]);
                    }
                    break;
                case FunctionCode.ENCODETOUNI:
                    {
                        //int length = Encoding.UTF32.GetEncoder().GetByteCount(target.ToCharArray(), 0, target.Length, false);
                        //byte[] bytes = new byte[length];
                        //Encoding.UTF32.GetEncoder().GetBytes(target.ToCharArray(), 0, target.Length, bytes, 0, false);
                        //vEvaluator.setEncodingResult(bytes);
                        term = ((ExpressionArgument)func.Argument).Term;
                        string target = term.GetStrValue(exm);

                        int length = vEvaluator.RESULT_ARRAY.Length;
                        // result:0には長さが入るのでその分-1
                        if (target.Length > length - 1)
                            throw new CodeEE(String.Format("ENCODETOUNIの引数が長すぎます(現在{0}文字。最大{1}文字まで)", target.Length, length - 1));

                        int[] ary = new int[target.Length];
                        for (int i = 0; i < target.Length; i++)
                            ary[i] = char.ConvertToUtf32(target, i);
                        vEvaluator.SetEncodingResult(ary);
                    }
                    break;
                case FunctionCode.ASSERT:
                    if (((ExpressionArgument)func.Argument).Term.GetIntValue(exm) == 0)
                        throw new CodeEE("ASSERT文の引数が0です");
                    break;
                case FunctionCode.THROW:
                    throw new CodeEE(((ExpressionArgument)func.Argument).Term.GetStrValue(exm));
            #if DEBUG
                default:
                    throw new ExeEE("未定義の関数");
            #endif
            }
            return;
        }
Esempio n. 10
0
 public void CopyArray(VariableToken var1, VariableToken var2)
 {
     if (var1.IsInteger)
     {
         if (var1.IsArray1D)
         {
             Int64[] array1 = (Int64[])var1.GetArray();
             Int64[] array2 = (Int64[])var2.GetArray();
             int length = (array1.Length >= array2.Length) ? array2.Length : array1.Length;
             for (int i = 0; i < length; i++)
                 array2[i] = array1[i];
         }
         else if (var1.IsArray2D)
         {
             Int64[,] array1 = (Int64[,])var1.GetArray();
             Int64[,] array2 = (Int64[,])var2.GetArray();
             int length1 = (array1.GetLength(0) >= array2.GetLength(0)) ? array2.GetLength(0) : array1.GetLength(0);
             int length2 = (array1.GetLength(1) >= array2.GetLength(1)) ? array2.GetLength(1) : array1.GetLength(1);
             for (int i = 0; i < length1; i++)
             {
                 for (int j = 0; j < length2; j++)
                     array2[i, j] = array1[i, j];
             }
         }
         else
         {
             Int64[, ,] array1 = (Int64[, ,])var1.GetArray();
             Int64[, ,] array2 = (Int64[, ,])var2.GetArray();
             int length1 = (array1.GetLength(0) >= array2.GetLength(0)) ? array2.GetLength(0) : array1.GetLength(0);
             int length2 = (array1.GetLength(1) >= array2.GetLength(1)) ? array2.GetLength(1) : array1.GetLength(1);
             int length3 = (array1.GetLength(2) >= array2.GetLength(2)) ? array2.GetLength(2) : array1.GetLength(2);
             for (int i = 0; i < length1; i++)
             {
                 for (int j = 0; j < length2; j++)
                 {
                     for (int k = 0; k < length3; k++)
                         array2[i, j, k] = array1[i, j, k];
                 }
             }
         }
     }
     else
     {
         if (var1.IsArray1D)
         {
             string[] array1 = (string[])var1.GetArray();
             string[] array2 = (string[])var2.GetArray();
             int length = (array1.Length >= array2.Length) ? array2.Length : array1.Length;
             for (int i = 0; i < length; i++)
                 array2[i] = array1[i];
         }
         else if (var1.IsArray2D)
         {
             string[,] array1 = (string[,])var1.GetArray();
             string[,] array2 = (string[,])var2.GetArray();
             int length1 = (array1.GetLength(0) >= array2.GetLength(0)) ? array2.GetLength(0) : array1.GetLength(0);
             int length2 = (array1.GetLength(1) >= array2.GetLength(1)) ? array2.GetLength(1) : array1.GetLength(1);
             for (int i = 0; i < length1; i++)
             {
                 for (int j = 0; j < length2; j++)
                     array2[i, j] = array1[i, j];
             }
         }
         else
         {
             string[, ,] array1 = (string[, ,])var1.GetArray();
             string[, ,] array2 = (string[, ,])var2.GetArray();
             int length1 = (array1.GetLength(0) >= array2.GetLength(0)) ? array2.GetLength(0) : array1.GetLength(0);
             int length2 = (array1.GetLength(1) >= array2.GetLength(1)) ? array2.GetLength(1) : array1.GetLength(1);
             int length3 = (array1.GetLength(2) >= array2.GetLength(2)) ? array2.GetLength(2) : array1.GetLength(2);
             for (int i = 0; i < length1; i++)
             {
                 for (int j = 0; j < length2; j++)
                 {
                     for (int k = 0; k < length3; k++)
                         array2[i, j, k] = array1[i, j, k];
                 }
             }
         }
     }
 }
Esempio n. 11
0
 internal Int64 FindChara(VariableToken varID, Int64 elem64, Int64 word, Int64 startIndex, Int64 lastIndex, bool isLast)
 {
     if (startIndex >= lastIndex)
         return -1;
     FixedVariableTerm fvp = new FixedVariableTerm(varID);
     if(varID.IsArray1D)
         fvp.Index2 = elem64;
     else if (varID.IsArray2D)
     {
         fvp.Index2 = elem64 >> 32;
         fvp.Index3 = elem64 & 0x7FFFFFFF;
     }
     int count = varData.CharacterList.Count;
     if (isLast)
     {
         for (Int64 i = lastIndex - 1; i >= startIndex; i--)
         {
             fvp.Index1 = i;
             if (word == fvp.GetIntValue(null))
                 return i;
         }
     }
     else
     {
         for (Int64 i = startIndex; i < lastIndex; i++)
         {
             fvp.Index1 = i;
             if (word == fvp.GetIntValue(null))
                 return i;
         }
     }
     return -1;
 }
Esempio n. 12
0
 /// <summary>
 /// RESULTに配列のサイズを代入。二次元配列ならRESULT:1に二番目のサイズを代入。三次元配列ならRESULT:1に二番目、RESULT:2に三番目のサイズを代入
 /// </summary>
 /// <param name="varID"></param>
 /// <returns></returns>
 public void VarSize(VariableToken varID)
 {
     Int64[] resultArray = RESULT_ARRAY;
     if (varID.IsArray2D)
     {
         resultArray[0] = varID.GetLength(0);
         resultArray[1] = varID.GetLength(1);
     }
     else if (varID.IsArray3D)
     {
         resultArray[0] = varID.GetLength(0);
         resultArray[1] = varID.GetLength(1);
         resultArray[2] = varID.GetLength(2);
     }
     else
     {
         resultArray[0] = varID.GetLength();
     }
 }
Esempio n. 13
0
        public void SortChara(VariableToken sortkey, Int64 elem, SortOrder sortorder, bool fixMaster)
        {
            if (varData.CharacterList.Count <= 1)
                return;
            if (sortorder == SortOrder.UNDEF)
                sortorder = SortOrder.ASCENDING;
            if (sortkey == null)
                sortkey = GlobalStatic.VariableData.GetSystemVariableToken("NO");
            CharacterData masterChara = null;
            CharacterData targetChara = null;
            CharacterData assiChara = null;
            if (this.MASTER >= 0 && this.MASTER < varData.CharacterList.Count)
                masterChara = varData.CharacterList[(int)this.MASTER];
            if (this.TARGET >= 0 && this.TARGET < varData.CharacterList.Count)
                targetChara = varData.CharacterList[(int)this.TARGET];
            if (this.ASSI >= 0 && this.ASSI < varData.CharacterList.Count)
                assiChara = varData.CharacterList[(int)this.ASSI];

            for (int i = 0; i < varData.CharacterList.Count; i++)
            {
                varData.CharacterList[i].temp_CurrentOrder = i;
                varData.CharacterList[i].SetSortKey(sortkey, elem);
            }
            if ((fixMaster) && (masterChara != null))
            {
                if (varData.CharacterList.Count <= 2)
                    return;
                varData.CharacterList.Remove(masterChara);
            }
            if (sortorder == SortOrder.ASCENDING)
                varData.CharacterList.Sort(CharacterData.AscCharacterComparison);
            else// if (sortorder == SortOrder.DESENDING)
                varData.CharacterList.Sort(CharacterData.DescCharacterComparison);
            //引数解析でチェック済み
            //else
            //    throw new ExeEE("ソート順序不明");

            if ((fixMaster) && (masterChara != null))
            {
                varData.CharacterList.Insert((int)this.MASTER, masterChara);
            }
            for (int i = 0; i < varData.CharacterList.Count; i++)
                varData.CharacterList[i].temp_CurrentOrder = i;
            if ((masterChara != null) && (!fixMaster))
                this.MASTER = masterChara.temp_CurrentOrder;
            if (targetChara != null)
                this.TARGET = targetChara.temp_CurrentOrder;
            if (assiChara != null)
                this.ASSI = assiChara.temp_CurrentOrder;
        }
Esempio n. 14
0
        public void SaveVariable(int saveIndex, string savMes, VariableToken[] vars)
        {
            string filepath = getSaveDataPathV(saveIndex);
            EraBinaryDataWriter bWriter = null;
            FileStream fs = null;
            try
            {
                Config.CreateSavDir();
                fs = new FileStream(filepath, FileMode.Create, FileAccess.Write);
                bWriter = new EraBinaryDataWriter(fs);
                bWriter.WriteHeader();
                bWriter.WriteFileType(EraSaveFileType.Var);
                bWriter.WriteInt64(gamebase.ScriptUniqueCode);
                bWriter.WriteInt64(gamebase.ScriptVersion);
                bWriter.WriteString(savMes);

                for(int i = 0; i < vars.Length; i++)
                    bWriter.WriteWithKey(vars[i].Name, vars[i].GetArray());
                bWriter.WriteEOF();
                RESULT = 1;
                return;
            }
            catch (Exception)
            {
                RESULT = 0;
                return;
            }
            finally
            {
                if (bWriter != null)
                    bWriter.Close();
                else if (fs != null)
                    fs.Close();
            }
        }
Esempio n. 15
0
 public SpVarsizeArgument(VariableToken var)
 {
     VariableID = var;
 }
 internal void AddUseDefinedVariable(VariableToken var)
 {
     varTokenDic.Add(var.Name, var);
     nameDic.Add(var.Name, DefinedNameType.UserGlobalVariable);
 }
Esempio n. 17
0
 public static VariableTerm ReduceVariable(VariableToken id, IOperandTerm p1, IOperandTerm p2, IOperandTerm p3)
 {
     IOperandTerm[] terms = null;
     IOperandTerm op1 = p1;
     IOperandTerm op2 = p2;
     IOperandTerm op3 = p3;
     //引数の推測
     if (id.IsCharacterData)
     {
         if (id.IsArray2D)
         {
             if ((op1 == null) || (op2 == null) || (op3 == null))
                 throw new CodeEE("キャラクタ二次元配列変数" + id.Name + "の引数は省略できません");
             terms = new IOperandTerm[3];
             terms[0] = op1;
             terms[1] = op2;
             terms[2] = op3;
         }
         else if (id.IsArray1D)
         {
             if (op3 != null)
                 throw new CodeEE("キャラクタ変数" + id.Name + "の引数が多すぎます");
             if (op2 == null)
             {
                 if (op1 == null)
                     op1 = ZeroTerm;
                 op2 = op1;
                 op1 = TARGET;
             }
             terms = new IOperandTerm[2];
             terms[0] = op1;
             terms[1] = op2;
         }
         else
         {
             if (op2 != null)
                 throw new CodeEE("一次元配列変数" + id.Name + "の引数が多すぎます");
             if (op1 == null)
                 op1 = TARGET;
             terms = new IOperandTerm[1];
             terms[0] = op1;
         }
     }
     else if (id.IsArray3D)
     {
         if ((op1 == null) || (op2 == null) || (op3 == null))
             throw new CodeEE("三次元配列変数" + id.Name + "の引数は省略できません");
         terms = new IOperandTerm[3];
         terms[0] = op1;
         terms[1] = op2;
         terms[2] = op3;
     }
     else if (id.IsArray2D)
     {
         if ((op1 == null) || (op2 == null))
             throw new CodeEE("二次元配列変数" + id.Name + "の引数は省略できません");
         if (op3 != null)
             throw new CodeEE("二次元配列" + id.Name + "の引数が多すぎます");
         terms = new IOperandTerm[2];
         terms[0] = op1;
         terms[1] = op2;
     }
     else if (id.IsArray1D)
     {
         if (op2 != null)
             throw new CodeEE("一次元配列変数" + id.Name + "の引数が多すぎます");
         if (op1 == null)
             op1 = ZeroTerm;
         terms = new IOperandTerm[1];
         terms[0] = op1;
     }
     else if (op1 != null)
     {
         throw new CodeEE("配列でない変数" + id.Name + "を引数付きで呼び出しています");
     }
     else
         terms = new IOperandTerm[0];
     for (int i = 0; i < terms.Length; i++)
         if (terms[i].IsString)
             terms[i] = new VariableStrArgTerm(id.Code, terms[i], i);
     return new VariableTerm(id, terms);
 }
Esempio n. 18
0
 public SpSaveVarArgument(IOperandTerm term, IOperandTerm mes, VariableToken[] varTokens)
 {
     Term = term;
     SavMes = mes;
     VarTokens = varTokens;
 }