예제 #1
0
        public void Construct(CommonTree syntaxClass)
        {
            Name = syntaxClass.Children[0].Text;
            var syntaxModifiers = syntaxClass.GetChild(1).CastTo <CommonTree>();

            if (syntaxModifiers.ChildCount > 0)
            {
                syntaxModifiers.Children.ForEach(mod =>
                {
                    if (mod.Text == Modifiers.Extern)
                    {
                        ModifiersList.Add(Modifier.Extern);
                    }
                    else if (mod.Text == Modifiers.Static)
                    {
                        ModifiersList.Add(Modifier.Static);
                    }
                    else
                    {
                        throw new Exception($"Modifier {mod.Text} is not defined");
                    }
                });
            }
            var classblock = syntaxClass.GetChild(2).CastTo <CommonTree>();

            if (classblock.ChildCount == 0)
            {
                return;
            }
            classblock.Children
            .Cast <CommonTree>()
            .ForEach(child =>
            {
                if (child.Type == MathLangParser.STATIC_DECLARATION)
                {
                    //List<VariableDeclaration> variableList
                    //    =  TreeHelper.RunMultiDeclaration(this, Scope, child.GetChild(0).CastTo<CommonTree>());
                    //VarDeclarationNodes.AddRange(variableList);
                    child.Children.Cast <CommonTree>()
                    .Select(syntaxVariableDeclaration =>
                    {
                        var variableDeclaration = TreeHelper
                                                  .GetStatements(this, Scope, syntaxVariableDeclaration).First()
                                                  .CastTo <VariableDeclaration>();
                        variableDeclaration.Construct(syntaxVariableDeclaration);
                        return(variableDeclaration);
                    })
                    .ForEach(declaration => VarDeclarationNodes.Add(declaration));
                }
                else if (child.Type == MathLangParser.FUNCDECLARATION)
                {
                    FunctionDeclaration function = new FunctionDeclaration(this, Scope);
                    FunctionDeclarationNodes.Add(function);
//                        Scope.AddFunction(function);
                    function.Construct(child);
                }
            });
        }
예제 #2
0
 protected AbstractReformValue(int id, DoubleConditionsList condition)
 {
     LifeQualityImpact = Procent.ZeroProcent.Copy();
     ID          = id;
     allowed     = condition;
     wantsReform = new Modifier(x => howIsItGoodForPop(x as PopUnit).get(), "Benefit to population", 1f, true);
     loyalty     = new Modifier(x => loyaltyBoostFor(x as PopUnit), "Loyalty", 1f, false);
     modVoting   = new ModifiersList(new List <Condition> {
         wantsReform, loyalty, education
     });
 }
예제 #3
0
        public ModifierGroupDto Clone(ProductDto productVm)
        {
            var res = new ModifierGroupDto();

            res.ID = ID;
            res.IncludeQuantity  = IncludeQuantity;
            res.IsAutoSel        = IsAutoSel;
            res.IsForceSel       = IsForceSel;
            res.IsPromptSel      = IsPromptSel;
            res.IsSeen           = IsSeen;
            res.IsSingleSel      = IsSingleSel;
            res.MaximumSelection = MaximumSelection;
            res.MinimumSelection = MinimumSelection;
            res.ModifiersList    = ModifiersList.Select(s => s.Clone(res)).ToList();
            res.Name             = Name;
            res.ParentModifier   = ParentModifier;
            res.Product          = productVm;
            res.Selected         = Selected;
            res.SelectionCount   = SelectionCount;
            return(res);
        }
예제 #4
0
    internal Factory(Province iprovince, Owner inowner, FactoryType intype)
    { //assuming this is level 0 building
        type           = intype;
        needsToUpgrade = type.getBuildNeeds();
        iprovince.allFactories.Add(this);
        factoryOwner = inowner;
        province     = iprovince;

        gainGoodsThisTurn = new Storage(type.basicProduction.getProduct());
        storageNow        = new Storage(type.basicProduction.getProduct());
        sentToMarket      = new Storage(type.basicProduction.getProduct());

        salary.set(province.getLocalMinSalary());


        modifierHasResourceInProvince = new Modifier(delegate(Country forWhom)
        {
            return(!type.isResourceGathering() && province.isProducingOnFactories(type.resourceInput));
        },
                                                     "Has input resource in thst province", true, 20f);
        modifierLevelBonus = new Modifier(delegate() { return(this.getLevel()); }, "High production concetration bonus", true, 5f);
        modifierInventedMiningAndIsShaft = new Modifier(
            delegate(Country forWhom)
        {
            return(forWhom.isInvented(InventionType.mining) && type.isShaft());
        },
            new StringBuilder("Invented ").Append(InventionType.mining.ToString()).ToString(), false, 50f);
        modifierBelongsToCountry = new Modifier(
            delegate(Country forWhom)
        {
            return(factoryOwner is Country);
        },
            "Belongs to government", false, -20f);

        modifierNotBelongsToCountry = new Condition(
            (Country x) => !(factoryOwner is Country),
            "Doesn't belongs to government", false);
        modifierIsSubsidised = new Modifier((x) => isSubsidized(), "Is subsidized", false, -10f);
        modifierEfficiency   = new ModifiersList(new List <Condition>()
        {
            new Modifier(InventionType.steamPower, true, 25f),
            modifierInventedMiningAndIsShaft,
            new Modifier(Economy.StateCapitalism, true, 10f),
            new Modifier(Economy.Interventionism, true, 30f),
            new Modifier(Economy.LaissezFaire, true, 50f),
            new Modifier(Economy.PlannedEconomy, true, -10f),
            modifierHasResourceInProvince, modifierLevelBonus,
            modifierBelongsToCountry, modifierIsSubsidised
        });

        conditionsUpgrade = new ConditionsList(new List <Condition>()
        {
            new Condition(delegate(Owner forWhom) { return(province.owner.economy.status != Economy.LaissezFaire || forWhom is PopUnit); }, "Economy policy is not Laissez Faire", true),
            new Condition(delegate(Owner forWhom) { return(!isUpgrading()); }, "Not upgrading", false),
            new Condition(delegate(Owner forWhom) { return(!isBuilding()); }, "Not building", false),
            new Condition(delegate(Owner forWhom) { return(isWorking()); }, "Open", false),
            new Condition(delegate(Owner forWhom) { return(level != Game.maxFactoryLevel); }, "Max level not achieved", false),
            new Condition(delegate(Owner forWhom) {
                Value cost = this.getUpgradeCost();
                return(forWhom.wallet.canPay(cost));
            }, delegate() {
                Game.threadDangerSB.Clear();
                Game.threadDangerSB.Append("Have ").Append(getUpgradeCost()).Append(" coins");
                return(Game.threadDangerSB.ToString());
            }, true)
        });

        conditionsClose = new ConditionsList(new List <Condition>()
        {
            new Condition(delegate(Owner forWhom) { return(province.owner.economy.status != Economy.LaissezFaire || forWhom is PopUnit); }, "Economy policy is not Laissez Faire", true),
            new Condition(delegate(Owner forWhom) { return(!isBuilding()); }, "Not building", false),
            new Condition(delegate(Owner forWhom) { return(isWorking()); }, "Open", false),
        });
        conditionsReopen = new ConditionsList(new List <Condition>()
        {
            new Condition(delegate(Owner forWhom) { return(province.owner.economy.status != Economy.LaissezFaire || forWhom is PopUnit); }, "Economy policy is not Laissez Faire", true),
            new Condition(delegate(Owner forWhom) { return(!isBuilding()); }, "Not building", false),
            new Condition(delegate(Owner forWhom) { return(!isWorking()); }, "Close", false),
            new Condition(delegate(Owner forWhom) {
                return(forWhom.wallet.canPay(getReopenCost()));
            }, delegate() {
                Game.threadDangerSB.Clear();
                Game.threadDangerSB.Append("Have ").Append(getReopenCost()).Append(" coins");
                return(Game.threadDangerSB.ToString());
            }, true)
        });
        conditionsDestroy = new ConditionsList(new List <Condition>()
        {
            Economy.isNotLF
        });
        //status == Economy.LaissezFaire || status == Economy.Interventionism || status == Economy.NaturalEconomy
        conditionsSell = ConditionsList.IsNotImplemented; // !Planned and ! State

        //(status == Economy.StateCapitalism || status == Economy.Interventionism || status == Economy.NaturalEconomy)
        conditionsBuy = ConditionsList.IsNotImplemented; // ! LF and !Planned

        // (status == Economy.PlannedEconomy || status == Economy.NaturalEconomy || status == Economy.StateCapitalism)
        conditionsNatinalize = new ConditionsList(new List <Condition>()
        {
            Economy.isNotLF, Economy.isNotInterventionism, modifierNotBelongsToCountry
        }); //!LF and ! Inter


        conditionsSubsidize = new ConditionsList(new List <Condition>()
        {
            Economy.isNotLF, Economy.isNotNatural
        });

        conditionsDontHireOnSubsidies = new ConditionsList(new List <Condition>()
        {
            Economy.isNotLF, Economy.isNotNatural, Condition.IsNotImplemented
        });

        conditionsChangePriority = new ConditionsList(new List <Condition>()
        {
            Economy.isNotLF, Condition.IsNotImplemented
        });
    }
예제 #5
0
        public void Construct(CommonTree syntaxFunctionDeclaration)
        {
            //Name
            Name = syntaxFunctionDeclaration.GetChild(0).Text;
            //Modifiers
            var syntaxModifiers = syntaxFunctionDeclaration.GetChild(1).CastTo <CommonTree>();

            if (syntaxModifiers.ChildCount > 0)
            {
                syntaxModifiers.Children.ForEach(mod =>
                {
                    if (mod.Text == Modifiers.Extern)
                    {
                        ModifiersList.Add(Modifier.Extern);
                    }
                    else if (mod.Text == Modifiers.Static)
                    {
                        ModifiersList.Add(Modifier.Static);
                    }
                    else
                    {
                        throw new Exception($"Modifier {mod.Text} is not defined");
                    }
                });
            }
            //Attributes
            var syntaxAttributeUsages = syntaxFunctionDeclaration.GetChild(2).CastTo <CommonTree>();

            if (syntaxAttributeUsages.ChildCount > 0)
            {
                syntaxAttributeUsages.Children.Cast <CommonTree>().ForEach(syntaxAttributeUsage =>
                {
                    AttributeUsage attributeUsage = new AttributeUsage(this, Scope);
                    attributeUsage.Construct(syntaxAttributeUsage);
                    AttributeUsages.Add(attributeUsage);
                });
            }
            //ReturnType
            string strType          = string.Empty;
            var    syntaxReturnType = syntaxFunctionDeclaration.GetChild(3).CastTo <CommonTree>();

            syntaxReturnType.Children.ForEach(node => strType += node.Text);
            //ReturnType = TreeHelper.GetReturnType(syntaxFunctionDeclaration.GetChild(1).GetChild(0).Text);
            ReturnType = TreeHelper.GetReturnType(strType);
            //Parameters
            var syntaxParametersNode = syntaxFunctionDeclaration.GetChild(4).CastTo <CommonTree>();

            if (syntaxParametersNode.ChildCount > 0)
            {
                syntaxParametersNode.Children.Cast <CommonTree>()
                .ForEach(syntaxParameter =>
                {
                    FunctionVariableDeclarationParameter functionVariableDeclarationParameter =
                        new FunctionVariableDeclarationParameter(this, Scope);
                    ParameterNodes.Add(functionVariableDeclarationParameter);
//                        Scope.AddVariable(functionDeclarationParameter);
                    functionVariableDeclarationParameter.Construct(syntaxParameter);
                });
            }

            //Statements
            var syntaxFunctionBody = syntaxFunctionDeclaration.GetChild(5).CastTo <CommonTree>();

            //StatemenBlock = TreeHelper.GetStatements(this, Scope, syntaxStatementBlock)
            //    .First().CastTo<BlockStatement>();
            if (syntaxFunctionBody.ChildCount > 0)
            {
                StatementBlock = new BlockStatement(this, Scope, false);
                StatementBlock.Construct(syntaxFunctionBody.GetChild(0).CastTo <CommonTree>());
            }
        }