public void BindDictionary(IDictionary <string, string> dictionary)
        {
            if (dictionary == null)
            {
                return;
            }

            foreach (var pair in dictionary)
            {
                if (string.IsNullOrEmpty(pair.Key))
                {
                    continue;
                }
                var key    = pair.Key;
                var values = pair.Value.Trim().Split('|');

                foreach (var token in values)
                {
                    if (string.IsNullOrWhiteSpace(token) || UnitMap.ContainsKey(token))
                    {
                        continue;
                    }
                    UnitMap.Add(token, key);
                }
            }
        }
Ejemplo n.º 2
0
        protected internal virtual Result <Unit> Link(Unit self, Reference mod)
        {
            if (!UnitMap.TryGetValue(mod, out Unit unit))
            {
                if (mod.ModuleName == nameof(lang))
                {
                    unit = lang;
                }
                else if (mod.DllName != null)
                {
                    unit = LinkForeignModule(self, mod);

                    if (unit == null)
                    {
                        AddError(LinkerError.AssemblyNotFound, mod.SourceFileName, mod.SourceLocation, mod.DllName, mod.ModuleName);
                    }
                }
                else
                {
                    var path = FindModule(self, mod.GetPath(), mod);

                    if (path != null && string.Equals(Path.GetExtension(path), EXT))
                    {
                        unit = ProcessSourceFile(path, mod);
                    }
                    else if (path != null)
                    {
                        unit = ProcessObjectFile(path, mod);
                    }
                }

                if (unit != null)
                {
                    unit.Id = Units.Count;
                    Units.Add(unit);
                    UnitMap.Add(mod, unit);
                }
            }

            if (unit != null && mod.Checksum != 0 && mod.Checksum != unit.Checksum && !BuilderOptions.LinkerSkipChecksum)
            {
                AddError(LinkerError.ChecksumValidationFailed, mod.SourceFileName, mod.SourceLocation, mod.ModuleName, unit.FileName);
            }

            return(Result.Create(unit, Messages));
        }
Ejemplo n.º 3
0
    // generate target army for this combat phase
    public UnitMap GenerateTargetArmy(UnitPriorities unitPriorities, BuildingType plannedBuilding)
    {
        UnitMap targetArmy          = new UnitMap(startingUnits);
        int     remainingSupplyCopy = remainingSupply;

        // while army not full (won't cause any issues as all units currently have 1 or 2 as their supplyCost, may need changes in future)
        while (remainingSupplyCopy > 0)
        {
            UnitPurchaseModel model = null;

            while (model == null)
            {
                model = RandomlySelectUnit(unitPriorities);
            }

            UnitType type = model.unitType;
            if (IsUnitTrainable(type, remainingSupplyCopy, plannedBuilding))
            {
                requiredWood        += model.buildCost.GetResourceAmount(ResourceType.WOOD);
                requiredMagicStone  += model.buildCost.GetResourceAmount(ResourceType.MAGIC_STONE);
                remainingSupplyCopy -= model.armySize;

                targetArmy.Add(type);
            }
            ;
        }

        // check if supply has gone negative
        if (remainingSupplyCopy != 0)
        {
            Debug.LogError("supply < 0? (=" + remainingSupplyCopy + ")");
        }

        Debug.Log(targetArmy.StatusString());
        return(targetArmy);
    }
Ejemplo n.º 4
0
 // Only to be called after combat to return "alive unit" to army
 public void AddUnit(UnitType type)
 {
     activeUnitNumbers.Add(type);
 }