Ejemplo n.º 1
0
        public void CreateSection(string Name)
        {
            Section newSection = new Section();
            newSection.Name = Name;

            Sections.Add(newSection);
        }
Ejemplo n.º 2
0
        public override TranslatorResult Translate(Section.SectionProperty INIProperty)
        {
            foreach ( OptionInterface item in _Options.Options )
            {
                if ( item.SaveKey.ToLower() != INIProperty.Name )
                {
                    continue;
                }
                if ( item is Option<KeyboardControl> )
                {
                    int unlessIndex = Convert.ToInt32(INIProperty.Value.ToLower().IndexOf("unless"));
                    string[] keysText = null;
                    string[] unlessKeysText = null;
                    if ( unlessIndex < 0 )
                    {
                        keysText = INIProperty.Value.Split(',');
                        unlessKeysText = new string[0];
                    }
                    else
                    {
                        keysText = INIProperty.Value.Substring(0, unlessIndex - 1).Split(',');
                        unlessKeysText = INIProperty.Value.Substring(unlessIndex + 6, INIProperty.Value.Length - (unlessIndex + 6)).Split(',');
                    }

                    Keys[] keys = new Keys[keysText.GetUpperBound(0) + 1];

                    bool valid = true;
                    for ( int j = 0; j <= keysText.GetUpperBound(0); j++ )
                    {
                        int number = 0;
                        if ( IOUtil.InvariantParse(keysText[j], ref number) )
                        {
                            keys[j] = (Keys)number;
                        }
                        else
                        {
                            valid = false;
                        }
                    }
                    Keys[] unlessKeys = new Keys[unlessKeysText.GetUpperBound(0) + 1];
                    for ( int j = 0; j <= unlessKeysText.GetUpperBound(0); j++ )
                    {
                        int number = 0;
                        if ( IOUtil.InvariantParse(unlessKeysText[j], ref number) )
                        {
                            unlessKeys[j] = (Keys)number;
                        }
                        else
                        {
                            valid = false;
                        }
                    }
                    if ( !valid )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    KeyboardControl control = new KeyboardControl(keys, unlessKeys);
                    if ( !item.IsValueValid(control) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<KeyboardControl>(control));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<SimpleList<string>> )
                {
                    SimpleList<string> list = default(SimpleList<string>);
                    if ( get_Changes(item) == null )
                    {
                        list = new SimpleList<string>();
                        set_Changes(item, new Change<SimpleList<string>>(list));
                    }
                    else
                    {
                        list = (SimpleList<string>)(get_Changes(item).ValueObject);
                    }
                    list.Add(INIProperty.Value);
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<FontFamily> )
                {
                    FontFamily fontFamily = default(FontFamily);
                    try
                    {
                        fontFamily = new FontFamily(Convert.ToString(INIProperty.Value));
                    }
                    catch
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(fontFamily) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<FontFamily>(fontFamily));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<clsRGB_sng> )
                {
                    clsRGB_sng value = new clsRGB_sng(0.0F, 0.0F, 0.0F);
                    if ( !value.ReadINIText(new SplitCommaText(Convert.ToString(INIProperty.Value))) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<clsRGB_sng>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<clsRGBA_sng> )
                {
                    clsRGBA_sng value = new clsRGBA_sng(0.0F, 0.0F, 0.0F, 0.0F);
                    if ( !value.ReadINIText(new SplitCommaText(Convert.ToString(INIProperty.Value))) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<clsRGBA_sng>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<bool> )
                {
                    bool value = default(bool);
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<bool>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<byte> )
                {
                    byte value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<byte>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<short> )
                {
                    short value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<short>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<int> )
                {
                    int value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<int>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<UInt32> )
                {
                    UInt32 value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<UInt32>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<Single> )
                {
                    float value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<Single>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<double> )
                {
                    double value = 0;
                    if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<double>(value));
                    return TranslatorResult.Translated;
                }
                else if ( item is Option<string> )
                {
                    string value = Convert.ToString(INIProperty.Value);
                    if ( !item.IsValueValid(value) )
                    {
                        return TranslatorResult.ValueInvalid;
                    }
                    set_Changes(item, new Change<string>(value));
                    return TranslatorResult.Translated;
                }
                else
                {
                    return TranslatorResult.ValueInvalid;
                }
            }

            return TranslatorResult.ValueInvalid;
        }
Ejemplo n.º 3
0
 public override TranslatorResult Translate(int INISectionNum, Section.SectionProperty INIProperty)
 {
     if ( (string)INIProperty.Name == "type" )
     {
         string[] CommaText = null;
         int CommaTextCount = 0;
         int A = 0;
         CommaText = INIProperty.Value.Split(',');
         CommaTextCount = CommaText.GetUpperBound(0) + 1;
         if ( CommaTextCount < 1 )
         {
             return TranslatorResult.ValueInvalid;
         }
         for ( A = 0; A <= CommaTextCount - 1; A++ )
         {
             CommaText[A] = Convert.ToString(CommaText[A].Trim());
         }
         switch ( CommaText[0].ToLower() )
         {
             case "feature":
                 Objects[INISectionNum].Type = clsUnitType.enumType.Feature;
                 Objects[INISectionNum].Code = CommaText[1];
                 break;
             case "structure":
                 Objects[INISectionNum].Type = clsUnitType.enumType.PlayerStructure;
                 Objects[INISectionNum].Code = CommaText[1];
                 break;
             case "droidtemplate":
                 Objects[INISectionNum].Type = clsUnitType.enumType.PlayerDroid;
                 Objects[INISectionNum].IsTemplate = true;
                 Objects[INISectionNum].Code = CommaText[1];
                 break;
             case "droiddesign":
                 Objects[INISectionNum].Type = clsUnitType.enumType.PlayerDroid;
                 break;
             default:
                 return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "droidtype" )
     {
         clsDroidDesign.clsTemplateDroidType DroidType = App.GetTemplateDroidTypeFromTemplateCode(Convert.ToString(INIProperty.Value));
         if ( DroidType == null )
         {
             return TranslatorResult.ValueInvalid;
         }
         Objects[INISectionNum].TemplateDroidType = DroidType;
     }
     else if ( (string)INIProperty.Name == "body" )
     {
         Objects[INISectionNum].BodyCode = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "propulsion" )
     {
         Objects[INISectionNum].PropulsionCode = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "turretcount" )
     {
         int NewTurretCount = 0;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref NewTurretCount) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( NewTurretCount < 0 | NewTurretCount > Constants.MaxDroidWeapons )
         {
             return TranslatorResult.ValueInvalid;
         }
         Objects[INISectionNum].TurretCount = NewTurretCount;
     }
     else if ( (string)INIProperty.Name == "turret1" )
     {
         string[] CommaText = null;
         int CommaTextCount = 0;
         int A = 0;
         CommaText = INIProperty.Value.Split(',');
         CommaTextCount = CommaText.GetUpperBound(0) + 1;
         if ( CommaTextCount < 2 )
         {
             return TranslatorResult.ValueInvalid;
         }
         for ( A = 0; A <= CommaTextCount - 1; A++ )
         {
             CommaText[A] = Convert.ToString(CommaText[A].Trim());
         }
         clsTurret.enumTurretType TurretType = default(clsTurret.enumTurretType);
         TurretType = App.GetTurretTypeFromName(CommaText[0]);
         if ( TurretType != clsTurret.enumTurretType.Unknown )
         {
             Objects[INISectionNum].TurretTypes[0] = TurretType;
             Objects[INISectionNum].TurretCodes[0] = CommaText[1];
         }
     }
     else if ( (string)INIProperty.Name == "turret2" )
     {
         string[] CommaText = null;
         int CommaTextCount = 0;
         int A = 0;
         CommaText = INIProperty.Value.Split(',');
         CommaTextCount = CommaText.GetUpperBound(0) + 1;
         if ( CommaTextCount < 2 )
         {
             return TranslatorResult.ValueInvalid;
         }
         for ( A = 0; A <= CommaTextCount - 1; A++ )
         {
             CommaText[A] = Convert.ToString(CommaText[A].Trim());
         }
         clsTurret.enumTurretType TurretType = default(clsTurret.enumTurretType);
         TurretType = App.GetTurretTypeFromName(CommaText[0]);
         if ( TurretType != clsTurret.enumTurretType.Unknown )
         {
             Objects[INISectionNum].TurretTypes[1] = TurretType;
             Objects[INISectionNum].TurretCodes[1] = CommaText[1];
         }
     }
     else if ( (string)INIProperty.Name == "turret3" )
     {
         string[] CommaText = null;
         int CommaTextCount = 0;
         int A = 0;
         CommaText = INIProperty.Value.Split(',');
         CommaTextCount = CommaText.GetUpperBound(0) + 1;
         if ( CommaTextCount < 2 )
         {
             return TranslatorResult.ValueInvalid;
         }
         for ( A = 0; A <= CommaTextCount - 1; A++ )
         {
             CommaText[A] = Convert.ToString(CommaText[A].Trim());
         }
         clsTurret.enumTurretType TurretType = default(clsTurret.enumTurretType);
         TurretType = App.GetTurretTypeFromName(CommaText[0]);
         if ( TurretType != clsTurret.enumTurretType.Unknown )
         {
             Objects[INISectionNum].TurretTypes[2] = TurretType;
             Objects[INISectionNum].TurretCodes[2] = CommaText[1];
         }
     }
     else if ( (string)INIProperty.Name == "id" )
     {
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), Objects[INISectionNum].ID) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "priority" )
     {
         Int32 temp_Result = Objects[INISectionNum].Priority;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref temp_Result) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "pos" )
     {
         string[] CommaText = null;
         int CommaTextCount = 0;
         int A = 0;
         CommaText = INIProperty.Value.Split(',');
         CommaTextCount = CommaText.GetUpperBound(0) + 1;
         if ( CommaTextCount < 2 )
         {
             return TranslatorResult.ValueInvalid;
         }
         for ( A = 0; A <= CommaTextCount - 1; A++ )
         {
             CommaText[A] = Convert.ToString(CommaText[A].Trim());
         }
         sXY_int Pos = new sXY_int();
         if ( !IOUtil.InvariantParse(CommaText[0], ref Pos.X) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( !IOUtil.InvariantParse(CommaText[1], ref Pos.Y) )
         {
             return TranslatorResult.ValueInvalid;
         }
         try
         {
             Objects[INISectionNum].Pos = new clsXY_int(Pos);
         }
         catch ( Exception )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "heading" )
     {
         double dblTemp = 0;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref dblTemp) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( dblTemp < 0.0D | dblTemp >= 360.0D )
         {
             return TranslatorResult.ValueInvalid;
         }
         Objects[INISectionNum].Heading = dblTemp;
     }
     else if ( (string)INIProperty.Name == "unitgroup" )
     {
         Objects[INISectionNum].UnitGroup = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "health" )
     {
         double NewHealth = 0;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref NewHealth) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( NewHealth < 0.0D | NewHealth >= 1.0D )
         {
             return TranslatorResult.ValueInvalid;
         }
         Objects[INISectionNum].Health = NewHealth;
     }
     else if ( (string)INIProperty.Name == "walltype" )
     {
         int WallType = -1;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref WallType) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( WallType >= 0 & WallType <= 3 )
         {
             Objects[INISectionNum].WallType = WallType;
         }
     }
     else if ( (string)INIProperty.Name == "scriptlabel" )
     {
         Objects[INISectionNum].Label = Convert.ToString(INIProperty.Value);
     }
     else
     {
         return TranslatorResult.NameUnknown;
     }
     return TranslatorResult.Translated;
 }
Ejemplo n.º 4
0
 public override TranslatorResult Translate(int INISectionNum, Section.SectionProperty INIProperty)
 {
     if ( (string)INIProperty.Name == "ax" )
     {
         int temp_Result = Gateways[INISectionNum].PosA.X;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref temp_Result) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "ay" )
     {
         Int32 temp_Result2 = Gateways[INISectionNum].PosA.Y;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref temp_Result2) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "bx" )
     {
         Int32 temp_Result3 = Gateways[INISectionNum].PosB.X;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref temp_Result3) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "by" )
     {
         int temp_Result4 = Gateways[INISectionNum].PosB.Y;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref temp_Result4) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else
     {
         return TranslatorResult.NameUnknown;
     }
     return TranslatorResult.Translated;
 }
Ejemplo n.º 5
0
 public override TranslatorResult Translate(Section.SectionProperty INIProperty)
 {
     if ( INIProperty.Name == "tileset" )
     {
         if ( INIProperty.Value.ToLower() == "arizona" )
         {
             Tileset = App.Tileset_Arizona;
         }
         else if ( INIProperty.Value.ToLower() == "urban" )
         {
             Tileset = App.Tileset_Urban;
         }
         else if ( INIProperty.Value.ToLower() == "rockies" )
         {
             Tileset = App.Tileset_Rockies;
         }
         else
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "size" )
     {
         string[] CommaText = INIProperty.Value.Split(',');
         if ( CommaText.GetUpperBound(0) + 1 < 2 )
         {
             return TranslatorResult.ValueInvalid;
         }
         int A = 0;
         for ( A = 0; A <= CommaText.GetUpperBound(0); A++ )
         {
             CommaText[A] = CommaText[A].Trim();
         }
         sXY_int NewSize = new sXY_int();
         if ( !IOUtil.InvariantParse(CommaText[0], ref NewSize.X) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( !IOUtil.InvariantParse(CommaText[1], ref NewSize.Y) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( NewSize.X < 1 | NewSize.Y < 1 | NewSize.X > Constants.MapMaxSize | NewSize.Y > Constants.MapMaxSize )
         {
             return TranslatorResult.ValueInvalid;
         }
         TerrainSize = NewSize;
     }
     else if ( (string)INIProperty.Name == "autoscrolllimits" )
     {
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref InterfaceOptions.AutoScrollLimits) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "scrollminx" )
     {
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref InterfaceOptions.ScrollMin.X) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "scrollminy" )
     {
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref InterfaceOptions.ScrollMin.Y) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "scrollmaxx" )
     {
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), InterfaceOptions.ScrollMax.X) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "scrollmaxy" )
     {
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), InterfaceOptions.ScrollMax.Y) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "name" )
     {
         InterfaceOptions.CompileName = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "players" )
     {
         InterfaceOptions.CompileMultiPlayers = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "xplayerlev" )
     {
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref InterfaceOptions.CompileMultiXPlayers) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "author" )
     {
         InterfaceOptions.CompileMultiAuthor = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "license" )
     {
         InterfaceOptions.CompileMultiLicense = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "camptime" )
     {
         //allow and ignore
     }
     else if ( (string)INIProperty.Name == "camptype" )
     {
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref InterfaceOptions.CampaignGameType) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else
     {
         return TranslatorResult.NameUnknown;
     }
     return TranslatorResult.Translated;
 }
Ejemplo n.º 6
0
        private clsResult Read_FMap_Info(StreamReader File, ref FMapInfo ResultInfo)
        {
            clsResult ReturnResult = new clsResult("Read general map info");

            Section InfoINI = new Section();
            ReturnResult.Take(InfoINI.ReadFile(File));

            ResultInfo = new FMapInfo();
            ReturnResult.Take(InfoINI.Translate(ResultInfo));

            if ( ResultInfo.TerrainSize.X < 0 | ResultInfo.TerrainSize.Y < 0 )
            {
                ReturnResult.ProblemAdd("Map size was not specified or was invalid.");
            }

            return ReturnResult;
        }
Ejemplo n.º 7
0
 public override TranslatorResult Translate(int INISectionNum, Section.SectionProperty INIProperty)
 {
     if ( (string)INIProperty.Name == "id" )
     {
         UInt32 uintTemp = 0;
         if ( IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), uintTemp) )
         {
             if ( uintTemp > 0 )
             {
                 Structures[INISectionNum].ID = uintTemp;
             }
         }
         else
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "name" )
     {
         Structures[INISectionNum].Code = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "startpos" )
     {
         int StartPos = 0;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref StartPos) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( StartPos < 0 | StartPos >= Constants.PlayerCountMax )
         {
             return TranslatorResult.ValueInvalid;
         }
         Structures[INISectionNum].UnitGroup = ParentMap.UnitGroups[StartPos];
     }
     else if ( (string)INIProperty.Name == "player" )
     {
         if ( INIProperty.Value.ToLower() != "scavenger" )
         {
             return TranslatorResult.ValueInvalid;
         }
         Structures[INISectionNum].UnitGroup = ParentMap.ScavengerUnitGroup;
     }
     else if ( (string)INIProperty.Name == "position" )
     {
         App.clsWorldPos temp_Result = Structures[INISectionNum].Pos;
         if ( !IOUtil.WorldPosFromINIText(Convert.ToString(INIProperty.Value), ref temp_Result) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "rotation" )
     {
         App.sWZAngle temp_Result2 = Structures[INISectionNum].Rotation;
         if ( !IOUtil.WZAngleFromINIText(Convert.ToString(INIProperty.Value), ref temp_Result2) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "modules" )
     {
         int ModuleCount = 0;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref ModuleCount) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( ModuleCount < 0 )
         {
             return TranslatorResult.ValueInvalid;
         }
         Structures[INISectionNum].ModuleCount = ModuleCount;
     }
     else if ( (string)INIProperty.Name == "health" )
     {
         int temp_Result3 = Structures[INISectionNum].HealthPercent;
         if ( !IOUtil.HealthFromINIText(Convert.ToString(INIProperty.Value), ref temp_Result3) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "wall/type" )
     {
         int WallType = 0;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref WallType) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( WallType < 0 )
         {
             return TranslatorResult.ValueInvalid;
         }
         Structures[INISectionNum].WallType = WallType;
     }
     else
     {
         return TranslatorResult.NameUnknown;
     }
     return TranslatorResult.Translated;
 }
Ejemplo n.º 8
0
 public override TranslatorResult Translate(int INISectionNum, Section.SectionProperty INIProperty)
 {
     if ( (string)INIProperty.Name == "id" )
     {
         UInt32 uintTemp = 0;
         if ( IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), uintTemp) )
         {
             if ( uintTemp > 0 )
             {
                 Features[INISectionNum].ID = uintTemp;
             }
         }
         else
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "name" )
     {
         Features[INISectionNum].Code = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "position" )
     {
         App.clsWorldPos temp_Result = Features[INISectionNum].Pos;
         if ( !IOUtil.WorldPosFromINIText(Convert.ToString(INIProperty.Value), ref temp_Result) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "rotation" )
     {
         App.sWZAngle temp_Result2 = Features[INISectionNum].Rotation;
         if ( !IOUtil.WZAngleFromINIText(Convert.ToString(INIProperty.Value), ref temp_Result2) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "health" )
     {
         Int32 temp_Result3 = Features[INISectionNum].HealthPercent;
         if ( !IOUtil.HealthFromINIText(Convert.ToString(INIProperty.Value), ref temp_Result3) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else
     {
         return TranslatorResult.NameUnknown;
     }
     return TranslatorResult.Translated;
 }
Ejemplo n.º 9
0
 public override TranslatorResult Translate(int INISectionNum, Section.SectionProperty INIProperty)
 {
     if ( (string)INIProperty.Name == "id" )
     {
         UInt32 uintTemp = 0;
         if ( IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), uintTemp) )
         {
             if ( uintTemp > 0 )
             {
                 Droids[INISectionNum].ID = uintTemp;
             }
         }
         else
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "template" )
     {
         Droids[INISectionNum].Template = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "startpos" )
     {
         int StartPos = 0;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref StartPos) )
         {
             return TranslatorResult.ValueInvalid;
         }
         if ( StartPos < 0 | StartPos >= Constants.PlayerCountMax )
         {
             return TranslatorResult.ValueInvalid;
         }
         Droids[INISectionNum].UnitGroup = ParentMap.UnitGroups[StartPos];
     }
     else if ( (string)INIProperty.Name == "player" )
     {
         if ( INIProperty.Value.ToLower() != "scavenger" )
         {
             return TranslatorResult.ValueInvalid;
         }
         Droids[INISectionNum].UnitGroup = ParentMap.ScavengerUnitGroup;
     }
     else if ( (string)INIProperty.Name == "name" )
     {
         //ignore
     }
     else if ( (string)INIProperty.Name == "position" )
     {
         App.clsWorldPos temp_Result = Droids[INISectionNum].Pos;
         if ( !IOUtil.WorldPosFromINIText(Convert.ToString(INIProperty.Value), ref temp_Result) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "rotation" )
     {
         App.sWZAngle temp_Result2 = Droids[INISectionNum].Rotation;
         if ( !IOUtil.WZAngleFromINIText(Convert.ToString(INIProperty.Value), ref temp_Result2) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "health" )
     {
         int temp_Result3 = Droids[INISectionNum].HealthPercent;
         if ( !IOUtil.HealthFromINIText(Convert.ToString(INIProperty.Value), ref temp_Result3) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "droidtype" )
     {
         int temp_Result4 = Droids[INISectionNum].DroidType;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref temp_Result4) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "weapons" )
     {
         Int32 temp_Result5 = Droids[INISectionNum].WeaponCount;
         if ( !IOUtil.InvariantParse(Convert.ToString(INIProperty.Value), ref temp_Result5) )
         {
             return TranslatorResult.ValueInvalid;
         }
     }
     else if ( (string)INIProperty.Name == "parts\\body" )
     {
         Droids[INISectionNum].Body = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "parts\\propulsion" )
     {
         Droids[INISectionNum].Propulsion = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "parts\\brain" )
     {
         Droids[INISectionNum].Brain = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "parts\\repair" )
     {
         Droids[INISectionNum].Repair = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "parts\\ecm" )
     {
         Droids[INISectionNum].ECM = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "parts\\sensor" )
     {
         Droids[INISectionNum].Sensor = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "parts\\construct" )
     {
         Droids[INISectionNum].Construct = Convert.ToString(INIProperty.Value);
     }
     else if ( (string)INIProperty.Name == "parts\\weapon\\1" )
     {
         Droids[INISectionNum].Weapons[0] = INIProperty.Value;
     }
     else if ( (string)INIProperty.Name == "parts\\weapon\\2" )
     {
         Droids[INISectionNum].Weapons[1] = INIProperty.Value;
     }
     else if ( (string)INIProperty.Name == "parts\\weapon\\3" )
     {
         Droids[INISectionNum].Weapons[2] = INIProperty.Value;
     }
     else
     {
         return TranslatorResult.NameUnknown;
     }
     return TranslatorResult.Translated;
 }
Ejemplo n.º 10
0
        public clsResult ReadFile(StreamReader File)
        {
            clsResult ReturnResult = new clsResult("Reading INI");

            int InvalidLineCount = 0;
            int CurrentEntryNum = -1;
            string LineText = null;
            int A = 0;
            string SectionName = "";

            RootSection = new Section();

            do
            {
                LineText = File.ReadLine();
                if ( LineText == null )
                {
                    break;
                }
                LineText = LineText.Trim();
                A = LineText.IndexOf('#');
                if ( A >= 0 )
                {
                    LineText = Strings.Left(LineText, A).Trim();
                }
                if ( LineText.Length >= 2 )
                {
                    if ( LineText[0] == '[' )
                    {
                        if ( LineText[LineText.Length - 1] == ']' )
                        {
                            SectionName = LineText.Substring(1, LineText.Length - 2);
                            for ( A = 0; A <= Sections.Count - 1; A++ )
                            {
                                if ( Sections[A].Name == SectionName )
                                {
                                    break;
                                }
                            }
                            CurrentEntryNum = A;
                            if ( CurrentEntryNum == Sections.Count )
                            {
                                CreateSection(SectionName);
                            }
                        }
                        else
                        {
                            InvalidLineCount++;
                        }
                    }
                    else if ( CurrentEntryNum >= 0 )
                    {
                        A = LineText.IndexOf('=');
                        if ( A >= 0 )
                        {
                            Sections[CurrentEntryNum].CreateProperty(LineText.Substring(0, A).ToLower().Trim(),
                                LineText.Substring(A + 1, LineText.Length - A - 1).Trim());
                        }
                        else
                        {
                            InvalidLineCount++;
                        }
                    }
                    else
                    {
                        A = LineText.IndexOf('=');
                        if ( A >= 0 )
                        {
                            RootSection.CreateProperty(LineText.Substring(0, A).ToLower().Trim(), LineText.Substring(A + 1, LineText.Length - A - 1).Trim());
                        }
                        else
                        {
                            InvalidLineCount++;
                        }
                    }
                }
                else if ( LineText.Length > 0 )
                {
                    InvalidLineCount++;
                }
            } while ( true );

            Sections.RemoveBuffer();

            if ( InvalidLineCount > 0 )
            {
                ReturnResult.WarningAdd("There were " + Convert.ToString(InvalidLineCount) + " invalid lines that were ignored.");
            }

            return ReturnResult;
        }