Exemplo n.º 1
0
 public MessageType getMessageType()
 {
     if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isAlwaysDisplay())
         {
             return(MessageType.ALwaysDisplay);
         }
         else if (ct.isDontAlwaysDisplay())
         {
             return(MessageType.DontAlwaysDisplay);
         }
     }
     else if (this is StringToken)
     {
         foreach (MessageType type in MessageType.AllDisplays)
         {
             if (type.ToString().Equals(this.content))
             {
                 return(type);
             }
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 2
0
        private Token getCommandToken(int position)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                char ch = getNextChar();
                if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || ch == ' ' || ch == '\'')
                {
                    sb.Append(ch);
                }
                else
                {
                    unreadLastChar();
                    CommandToken t = new CommandToken(sb.ToString(), position);
                    if (t.isValid())
                    {
                        return(t);
                    }
                    else     // Invalid trigger?
                    {
                        return(t);
                    }
                }
            }
        }
Exemplo n.º 3
0
 private bool parseLocations()
 {
     if (lastToken is CommandToken)
     {
         CommandToken ct = (CommandToken)lastToken;
         if (ct.isLocations())
         {
             if (getNextToken() is LeftBracket)
             {
                 Token num = getNextToken();
                 if (num is NumToken && getNextToken() is RightBracket && getNextToken() is Colon)
                 {
                     int locationsCount = num.toInt();
                     LocationDef.__setLocationsCountDoNotUseOutsideOfParser(locationsCount);
                     for (int i = 0; i < locationsCount; i++)
                     {
                         Token locName = getNextToken();
                         if (locName is NumToken)   // Unnamed location
                         {
                             LocationDef.__setLocationNameDontUseOutsideOfParser(i, "Location " + ((NumToken)locName).toInt());
                         }
                         else if (locName is StringToken)
                         {
                             LocationDef.__setLocationNameDontUseOutsideOfParser(i, ((StringToken)locName).toStringDef().ToString());
                         }
                         else if (locName is CommandToken)
                         {
                             if (((CommandToken)locName).isNoLocation())
                             {
                                 LocationDef.__setLocationNameDontUseOutsideOfParser(i, "No Location");
                             }
                             else
                             {
                                 throw new NotImplementedException();
                             }
                         }
                         else
                         {
                             throw new NotImplementedException();
                         }
                     }
                     return(true);
                 }
             }
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 4
0
 public SwitchState toSwitchState()
 {
     if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isSet())
         {
             return(SwitchState.Set);
         }
         else if (ct.isNotSet())
         {
             return(SwitchState.NotSet);
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
        private bool parseActions()
        {
            Token t         = getNextToken();
            bool  commented = false;

            if (t is Semicolon)   // Comment
            {
                commented = true;
                t         = getNextToken();
            }
            else
            {
                if (t is EndBracket)
                {
                    return(true);
                }
            }

            if (t is CommandToken)
            {
                CommandToken ct = t as CommandToken;
                if (ct.isFlags())
                {
                    if (parseFlags())
                    {
                        if (getNextToken() is EndBracket)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    Action a = getAction(ct);
                    a.setEnabled(!commented);
                    currentTrigger.addAction(a);
                    t = getNextToken();
                    if (t is Semicolon)
                    {
                        return(parseActions());
                    }
                }
            }
            throw new NotImplementedException();
        }
Exemplo n.º 6
0
        private bool parseStringTable()
        {
            Token qt = getNextToken();

            if (qt is CommandToken)
            {
                CommandToken ct = (CommandToken)qt;
                if (ct.isStrings())
                {
                    if (getNextToken() is LeftBracket)
                    {
                        qt = getNextToken();
                        if (qt is NumToken)
                        {
                            int stringTableLength = qt.toInt();
                            if (getNextToken() is RightBracket)
                            {
                                if (getNextToken() is Colon)
                                {
                                    string[] stringTable = new string[stringTableLength];
                                    for (int i = 0; i < stringTable.Length; i++)
                                    {
                                        qt = getNextToken();
                                        if (qt is StringToken)
                                        {
                                            stringTable[i] = qt.getContent();
                                            //Debug.Write("0");
                                        }
                                        else
                                        {
                                            throw new NotImplementedException();
                                        }
                                    }
                                    Token.StringTable = stringTable;
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            throw new NotImplementedException();
        }
Exemplo n.º 7
0
        private bool parseExtendedStringTable()
        {
            Token qt = getNextToken();

            if (qt is CommandToken)
            {
                CommandToken ct = (CommandToken)qt;
                if (getNextToken() is LeftBracket)
                {
                    if (ct.isExtendedStrings())
                    {
                        qt = getNextToken();
                        if (qt is NumToken)
                        {
                            int extendedStringsTableLength = ((NumToken)qt).toInt();
                            if (getNextToken() is RightBracket)
                            {
                                if (getNextToken() is Colon)
                                {
                                    string[] extendedStringTable = new string[extendedStringsTableLength];
                                    for (int i = 0; i < extendedStringTable.Length; i++)
                                    {
                                        qt = getNextToken();
                                        if (qt is StringToken)
                                        {
                                            extendedStringTable[i] = ((StringToken)qt).ToString();
                                        }
                                        else
                                        {
                                            throw new NotImplementedException();
                                        }
                                    }
                                    Token.ExtendedStringTable = extendedStringTable;
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            throw new NotImplementedException();
        }
Exemplo n.º 8
0
 public SetQuantifier toSetQuantifier()
 {
     if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isAdd())
         {
             return(SetQuantifier.Add);
         }
         else if (ct.isSubtract())
         {
             return(SetQuantifier.Subtract);
         }
         else if (ct.isSetTo())
         {
             return(SetQuantifier.SetTo);
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 public Order toOrder()
 {
     if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isMove())
         {
             return(Order.Move);
         }
         else if (ct.isAttack())
         {
             return(Order.Attack);
         }
         else if (ct.isPatrol())
         {
             return(Order.Patrol);
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 public AllianceDef toAlliance()
 {
     if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isAlliedVictory())
         {
             return(AllianceDef.AlliedVictory);
         }
         else if (ct.isAlly())
         {
             return(AllianceDef.Ally);
         }
         else if (ct.isEnemy())
         {
             return(AllianceDef.Enemy);
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
 public Resources toResources()
 {
     if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isOre())
         {
             return(Resources.Ore);
         }
         else if (ct.isGas())
         {
             return(Resources.Gas);
         }
         else if (ct.isOreAndGas())
         {
             return(Resources.OreAndGas);
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
 public EnableState toEnableState()
 {
     if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isDisabled())
         {
             return(EnableState.Disable);
         }
         else if (ct.isEnabled())
         {
             return(EnableState.Enable);
         }
         else if (ct.isToggle())
         {
             return(EnableState.Toggle);
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
 public Quantifier toQuantifier()
 {
     if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isAtLeast())
         {
             return(Quantifier.AtLeast);
         }
         else if (ct.isAtMost())
         {
             return(Quantifier.AtMost);
         }
         else if (ct.isExactly())
         {
             return(Quantifier.Exactly);
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 14
0
 public ScoreBoard toScoreBoard()
 {
     if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isBuildings())
         {
             return(ScoreBoard.Buildings);
         }
         else if (ct.isCustom())
         {
             return(ScoreBoard.Custom);
         }
         else if (ct.isKills())
         {
             return(ScoreBoard.Kills);
         }
         else if (ct.isKillsAndRazings())
         {
             return(ScoreBoard.KillsAndRazings);
         }
         else if (ct.isRazings())
         {
             return(ScoreBoard.Razings);
         }
         else if (ct.isTotal())
         {
             return(ScoreBoard.Total);
         }
         else if (ct.isUnits())
         {
             return(ScoreBoard.Units);
         }
         else if (ct.isUnitsAndBuildings())
         {
             return(ScoreBoard.UnitsAndBuildings);
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
        private bool parseUnitNames()
        {
            Token t = getNextToken();

            if (t is CommandToken)
            {
                CommandToken ct = t as CommandToken;
                if (ct.isUnits())
                {
                    if (getNextToken() is LeftBracket)
                    {
                        Token num = getNextToken();
                        if (num is NumToken)
                        {
                            if (getNextToken() is RightBracket)
                            {
                                if (getNextToken() is Colon)
                                {
                                    int unitsCount = num.toInt();
                                    for (int i = 0; i < unitsCount; i++)
                                    {
                                        Token unitName = getNextToken();
                                        if (unitName is StringToken)
                                        {
                                            UnitVanillaDef.__setUnitNameDontUseOutsideOfParser(i, ((StringToken)unitName).toStringDef().ToString());
                                        }
                                        else
                                        {
                                            throw new NotImplementedException();
                                        }
                                    }
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            throw new NotImplementedException();
        }
Exemplo n.º 16
0
        private bool parseConditions()
        {
            Token t         = getNextToken();
            bool  commented = false;

            if (t is Semicolon)   // Comment
            {
                commented = true;
                t         = getNextToken();
            }
            if (t is CommandToken)
            {
                CommandToken ct = t as CommandToken;
                if (ct.isActions())
                {
                    if (!commented)
                    {
                        if (getNextToken() is Colon)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    Condition c = GetCondition(ct);
                    c.setEnabled(!commented);
                    currentTrigger.addCondition(c);
                    t = getNextToken();
                    if (t is Semicolon)
                    {
                        return(parseConditions());
                    }
                }
            }
            throw new NotImplementedException();
        }
Exemplo n.º 17
0
 public SwitchSetState toSwitchSetState()
 {
     if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isClear())
         {
             return(SwitchSetState.Clear);
         }
         else if (ct.isRandomize())
         {
             return(SwitchSetState.Randomize);
         }
         else if (ct.isSet())
         {
             return(SwitchSetState.Set);
         }
         else if (ct.isToggle())
         {
             return(SwitchSetState.Toggle);
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 18
0
 public int toInt()
 {
     if (this is NumToken)
     {
         uint out1;
         if (uint.TryParse(content, out out1))
         {
             return((int)out1);
         }
         else
         {
             return(int.Parse(content));
         }
     }
     else if (this is CommandToken)
     {
         CommandToken ct = this as CommandToken;
         if (ct.isAll())
         {
             return(-1);
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 19
0
        private bool parseTriggers()
        {
            while (true)
            {
                currentTrigger = new Trigger();
                Token t = getNextToken();
                if (t == null)
                {
                    return(true);
                }
                else if (t is CommandToken)
                {
                    CommandToken ct = t as CommandToken;
                    if (ct.isTrigger())
                    {
                        if (getNextToken() is LeftBracket)
                        {
                            Token affectName = getNextToken();
                            allTriggers.Add(currentTrigger);
                            Token nt = affectName;
                            if (affectName is NumToken || affectName is RightBracket) // This is fuckery
                            {
                                if (affectName is NumToken)                           // This trigger belongs to somebody
                                {
                                    nt = getNextToken();
                                    currentTrigger.addAffectName(affectName);
                                    while (nt is Comma)
                                    {
                                        affectName = getNextToken();
                                        if (affectName is NumToken)
                                        {
                                            currentTrigger.addAffectName(affectName);
                                            nt = getNextToken();
                                        }
                                        else
                                        {
                                            throw new NotImplementedException();
                                        }
                                    }
                                }
                                else     // This trigger doesn't belong to anyone

                                {
                                }
                                if (nt is RightBracket)
                                {
                                    if (getNextToken() is StartBracket)
                                    {
                                        t = getNextToken();
                                        if (t is CommandToken)
                                        {
                                            ct = t as CommandToken;
                                            if (ct.isConditions())
                                            {
                                                if (getNextToken() is Colon)
                                                {
                                                    if (parseConditions())
                                                    {
                                                        if (parseActions())
                                                        {
                                                            if (getNextToken() is TokenEnd)
                                                            {
                                                                continue;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }
                throw new NotImplementedException();
            }
        }
Exemplo n.º 20
0
        private Condition GetCondition(CommandToken ct)
        {
            int position = ct.getPosition();

            if (ct.isAccumulate())
            {
                return(new ConditionAccumulate(this));
            }
            else if (ct.isAlways())
            {
                return(new ConditionAlways(this));
            }
            else if (ct.isBring())
            {
                return(new ConditionBring(this));
            }
            else if (ct.isCommand())
            {
                return(new ConditionCommand(this));
            }
            else if (ct.isCommandTheLeast())
            {
                return(new ConditionCommandTheLeast(this));
            }
            else if (ct.isCommandTheLeastAt())
            {
                return(new ConditionCommandTheLeastAt(this));
            }
            else if (ct.isCommandTheMost())
            {
                return(new ConditionCommandTheMost(this));
            }
            else if (ct.isCommandsTheMostAt())
            {
                return(new ConditionCommandsTheMostAt(this));
            }
            else if (ct.isCountdownTimer())
            {
                return(new ConditionCountdownTimer(this));
            }
            else if (ct.isDeaths())
            {
                ConditionDeaths d      = new ConditionDeaths(this);
                UnitVanillaDef  unit   = d.getUnitDef();
                PlayerDef       player = d.getPlayerDef();
                IntDef          amount = d.getAmount();
                Quantifier      q      = d.getQuantifier();
                if (unit.getIndex() > unit.getMaxValue())   // EUD Condition
                {
                    int pid  = player.getIndex();
                    int uid  = unit.getIndex();
                    int oid  = amount.getIndex();
                    int addr = (uid * 12) + pid;

                    ConditionMemory cm   = new ConditionMemory(new DummyParser(new Token[] { new LeftBracket(position), new NumToken(addr.ToString(), position), new Comma(position), new CommandToken(q.ToString(), position), new Comma(position), new NumToken(oid.ToString(), position), new RightBracket(position) }));
                    EPDCondition    cond = EPDCondition.get(cm);
                    if (cond != null)
                    {
                        return(cond);
                    }

                    return(cm);
                }

                return(d);
            }
            else if (ct.isElapsedTime())
            {
                return(new ConditionElapsedTime(this));
            }
            else if (ct.isHighestScore())
            {
                return(new ConditionHighestScore(this));
            }
            else if (ct.isKill())
            {
                return(new ConditionKill(this));
            }
            else if (ct.isLeastKills())
            {
                return(new ConditionLeastKills(this));
            }
            else if (ct.isLeastResources())
            {
                return(new ConditionLeastResources(this));
            }
            else if (ct.isLowestScore())
            {
                return(new ConditionLowestScore(this));
            }
            else if (ct.isMostKills())
            {
                return(new ConditionMostKills(this));
            }
            else if (ct.isMostResources())
            {
                return(new ConditionMostResources(this));
            }
            else if (ct.isNever())
            {
                return(new ConditionNever(this));
            }
            else if (ct.isOpponents())
            {
                return(new ConditionOpponents(this));
            }
            else if (ct.isScore())
            {
                return(new ConditionScore(this));
            }
            else if (ct.isSwitch())
            {
                return(new ConditionSwitch(this));
            }
            else if (ct.isMemory())
            {
                ConditionMemory cm   = new ConditionMemory(this);
                EPDCondition    cond = EPDCondition.get(cm);
                if (cond != null)
                {
                    return(cond);
                }
                return(cm);
            }
            else if (ct.isCustom())
            {
                return(new ConditionCustom(this));
            }
            throw new NotImplementedException();
        }
Exemplo n.º 21
0
 private Action getAction(CommandToken ct)
 {
     if (ct.isCenterView())
     {
         return(new ActionCenterView(this));
     }
     else if (ct.isComment())
     {
         return(new ActionComment(this));
     }
     else if (ct.isCreateUnit())
     {
         return(new ActionCreateUnit(this));
     }
     else if (ct.isCreateUnitWithProperties())
     {
         return(new ActionCreateUnitWithProperties(this));
     }
     else if (ct.isDefeat())
     {
         return(new ActionDefeat(this));
     }
     else if (ct.isDisplayTextMessage())
     {
         return(new ActionDisplayTextMessage(this));
     }
     else if (ct.isDraw())
     {
         return(new ActionDraw(this));
     }
     else if (ct.isGiveUnitsToPlayer())
     {
         return(new ActionGiveUnitsToPlayer(this));
     }
     else if (ct.isKillUnit())
     {
         return(new ActionKillUnit(this));
     }
     else if (ct.isKillUnitAtLocation())
     {
         return(new ActionKillUnitAtLocation(this));
     }
     else if (ct.isLeaderBoardControlAtLocation())
     {
         return(new ActionLeaderBoardControlAtLocation(this));
     }
     else if (ct.isLeaderBoardControl())
     {
         return(new ActionLeaderBoardControl(this));
     }
     else if (ct.isLeaderboardGreed())
     {
         return(new ActionLeaderboardGreed(this));
     }
     else if (ct.isLeaderBoardKills())
     {
         ActionLeaderBoardKills act = new ActionLeaderBoardKills(this);
         int[]          mapping     = ActionLeaderBoardKills.getTextMapping();
         int            unitIndex   = mapping[0];
         UnitVanillaDef unit        = act.get <UnitVanillaDef>(unitIndex);
         if (unit.getIndex() > unit.getMaxValue())
         {
             return(new ActionLeaderBoardDeaths(act));
         }
         return(act);
     }
     else if (ct.isLeaderBoardPoints())
     {
         return(new ActionLeaderBoardPoints(this));
     }
     else if (ct.isLeaderBoardResources())
     {
         return(new ActionLeaderBoardResources(this));
     }
     else if (ct.isLeaderboardComputerPlayers())
     {
         return(new ActionLeaderboardComputerPlayers(this));
     }
     else if (ct.isLeaderboardGoalControlAtLocation())
     {
         return(new ActionLeaderboardGoalControlAtLocation(this));
     }
     else if (ct.isLeaderboardGoalControl())
     {
         return(new ActionLeaderboardGoalControl(this));
     }
     else if (ct.isLeaderboardGoalKills())
     {
         return(new ActionLeaderboardGoalKills(this));
     }
     else if (ct.isLeaderboardGoalPoints())
     {
         return(new ActionLeaderboardGoalPoints(this));
     }
     else if (ct.isLeaderboardGoalResources())
     {
         return(new ActionLeaderboardGoalResources(this));
     }
     else if (ct.isMinimapPing())
     {
         return(new ActionMinimapPing(this));
     }
     else if (ct.isModifyUnitEnergy())
     {
         return(new ActionModifyUnitEnergy(this));
     }
     else if (ct.isModifyUnitHangerCount())
     {
         return(new ActionModifyUnitHangerCount(this));
     }
     else if (ct.isModifyUnitHitPoints())
     {
         return(new ActionModifyUnitHitPoints(this));
     }
     else if (ct.isModifyUnitResourceAmount())
     {
         return(new ActionModifyUnitResourceAmount(this));
     }
     else if (ct.isModifyUnitShieldPoints())
     {
         return(new ActionModifyUnitShieldPoints(this));
     }
     else if (ct.isMoveLocation())
     {
         return(new ActionMoveLocation(this));
     }
     else if (ct.isPlayWAV())
     {
         return(new ActionPlayWAV(this));
     }
     else if (ct.isMoveUnit())
     {
         return(new ActionMoveUnit(this));
     }
     else if (ct.isMuteUnitSpeech())
     {
         return(new ActionMuteUnitSpeech(this));
     }
     else if (ct.isOrder())
     {
         return(new ActionOrder(this));
     }
     else if (ct.isPauseGame())
     {
         return(new ActionPauseGame(this));
     }
     else if (ct.isPauseTimer())
     {
         return(new ActionPauseTimer(this));
     }
     else if (ct.isPreserveTrigger())
     {
         return(new ActionPreserveTrigger(this));
     }
     else if (ct.isRemoveUnit())
     {
         return(new ActionRemoveUnit(this));
     }
     else if (ct.isRemoveUnitAtLocation())
     {
         return(new ActionRemoveUnitAtLocation(this));
     }
     else if (ct.isRunAIScript())
     {
         return(new ActionRunAIScript(this));
     }
     else if (ct.isRunAIScriptAtLocation())
     {
         return(new ActionRunAIScriptAtLocation(this));
     }
     else if (ct.isSetAllianceStatus())
     {
         return(new ActionSetAllianceStatus(this));
     }
     else if (ct.isSetCountdownTimer())
     {
         return(new ActionSetCountdownTimer(this));
     }
     else if (ct.isSetDeaths())
     {
         RawActionSetDeaths rawDeaths = new RawActionSetDeaths(this);
         Action             epd       = EPDAction.getFromDeathAction(rawDeaths);
         if (epd != null)
         {
             return(epd);
         }
         else
         {
             try {
                 return(new ActionSetDeaths(rawDeaths));
             } catch (NotImplementedException) {
                 return(rawDeaths);
             }
             //return rawDeaths;
         }
     }
     else if (ct.isSetDoodadState())
     {
         return(new ActionSetDoodadState(this));
     }
     else if (ct.isSetInvincibility())
     {
         return(new ActionSetInvincibility(this));
     }
     else if (ct.isSetMissionObjectives())
     {
         return(new ActionSetMissionObjectives(this));
     }
     else if (ct.isSetNextScenario())
     {
         return(new ActionSetNextScenario(this));
     }
     else if (ct.isSetResources())
     {
         return(new ActionSetResources(this));
     }
     else if (ct.isSetScore())
     {
         return(new ActionSetScore(this));
     }
     else if (ct.isSetSwitch())
     {
         return(new ActionSetSwitch(this));
     }
     else if (ct.isTalkingPortrait())
     {
         return(new ActionTalkingPortrait(this));
     }
     else if (ct.isTransmission())
     {
         return(new ActionTransmission(this));
     }
     else if (ct.isUnmuteUnitSpeech())
     {
         return(new ActionUnmuteUnitSpeech(this));
     }
     else if (ct.isUnpauseGame())
     {
         return(new ActionUnpauseGame(this));
     }
     else if (ct.isUnpauseTimer())
     {
         return(new ActionUnpauseTimer(this));
     }
     else if (ct.isVictory())
     {
         return(new ActionVictory(this));
     }
     else if (ct.isWait())
     {
         return(new ActionWait(this));
     }
     throw new NotImplementedException();
 }