private SimRuleCommand ParseCommand(string line)
    {
        string[] lineSplit       = SplitLine(line);
        int      lineSplitOffset = 0;

        SimRuleCommand command = null;

        //Find target
        SimRuleValue target = null;

        switch (lineSplit[lineSplitOffset])
        {
        case "local":
            target = new SimRuleValueLocal();
            ((SimRuleValueLocal)target).resource = definition.GetResource(lineSplit[1]);
            lineSplitOffset += 2;
            break;

        case "global":
            target = new SimRuleValueGlobal();
            ((SimRuleValueGlobal)target).resource = definition.GetResource(lineSplit[1]);
            lineSplitOffset += 2;
            break;

        case "map":
            target = new SimRuleValueMap();
            ((SimRuleValueMap)target).mapId = lineSplit[1];
            lineSplitOffset += 2;
            break;

        case "agent":
            command = new SimRuleCommandAgent();
            ((SimRuleCommandAgent)command).agentType = definition.GetAgentType(lineSplit[1]);
            lineSplitOffset += 2;

            while (lineSplitOffset < lineSplit.Length)
            {
                switch (lineSplit[lineSplitOffset++])
                {
                case "to":
                    ((SimRuleCommandAgent)command).searchTarget = lineSplit[lineSplitOffset++];
                    break;

                case "add":
                    ((SimRuleCommandAgent)command).resources = ParseResourcesArray(lineSplit, ref lineSplitOffset);
                    break;

                default:
                    ThrowInvalidLine("ParseCommand() - Invalid agent parameter");
                    break;
                }
            }
            break;
        }

        if (target != null)
        {
            switch (lineSplit[lineSplitOffset])
            {
            case "add":
                command = new SimRuleCommandAdd();
                ((SimRuleCommandAdd)command).target = target;
                ((SimRuleCommandAdd)command).amount = ParseInt(lineSplit[lineSplitOffset + 1]);
                break;

            case "remove":
                command = new SimRuleCommandRemove();
                ((SimRuleCommandRemove)command).target = target;
                ((SimRuleCommandRemove)command).amount = ParseInt(lineSplit[lineSplitOffset + 1]);
                break;

            case "greater":
                command = new SimRuleCommandTest();
                ((SimRuleCommandTest)command).target     = target;
                ((SimRuleCommandTest)command).comparison = SimRuleCommandTest.Comparison.Greater;
                ((SimRuleCommandTest)command).amount     = ParseInt(lineSplit[lineSplitOffset + 1]);
                break;

            case "less":
                command = new SimRuleCommandTest();
                ((SimRuleCommandTest)command).target     = target;
                ((SimRuleCommandTest)command).comparison = SimRuleCommandTest.Comparison.Less;
                ((SimRuleCommandTest)command).amount     = ParseInt(lineSplit[lineSplitOffset + 1]);
                break;

            case "equals":
                command = new SimRuleCommandTest();
                ((SimRuleCommandTest)command).target     = target;
                ((SimRuleCommandTest)command).comparison = SimRuleCommandTest.Comparison.Equals;
                ((SimRuleCommandTest)command).amount     = ParseInt(lineSplit[lineSplitOffset + 1]);
                break;
            }
        }

        return(command);
    }