コード例 #1
0
        //读剧本和读存档都调用了此函数
        private void LoadGameDataFromDataBase(OleDbConnection DbConnection, string connectionString)
        {
            try
            {
                this.GameCommonData.LoadFromDatabase(connectionString);
                UsingOwnCommonData = true;
            }
            catch (Exception)
            {
                this.GameCommonData.Clear();
                this.LoadCommonData();
                UsingOwnCommonData = false;
            }
            try
            {
                this.LoadSettingsFromDatabase(connectionString);
            }
            catch (Exception)
            {
                //ignore
            }

            ExtensionInterface.loadCompiledTypes();

            this.scenarioJustLoaded = true;
            OleDbCommand command = new OleDbCommand("Select * From Map", DbConnection);
            ////////////////////////////////////////////////////////////////////////////////////////////
            DbConnection.Open();
            OleDbDataReader reader = command.ExecuteReader();
            reader.Read();
            this.ScenarioMap.MapName = reader["FileName"].ToString();
            this.ScenarioMap.TileWidth = (short)reader["TileWidth"];
            try
            {
                this.ScenarioMap.NumberOfTiles = (short)reader["kuaishu"];
                this.ScenarioMap.NumberOfSquaresInEachTile = (short)reader["meikuaidexiaokuaishu"];
                this.ScenarioMap.UseSimpleArchImages = (bool)reader["useSimpleArchImages"];
            }
            catch
            {
                this.ScenarioMap.NumberOfTiles = 20;
                this.ScenarioMap.NumberOfSquaresInEachTile = 10;
                this.ScenarioMap.UseSimpleArchImages = false;
            }
            this.ScenarioMap.LoadMapData(reader["MapData"].ToString(), (short)reader["DimensionX"], (short)reader["DimensionY"]);
            DbConnection.Close();
            ///////////////////////////////////////////////////////////////////////////////////////////
            DbConnection.Open();
            reader = new OleDbCommand("Select * From State", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                State t = new State();
                t.ID = (short)reader["ID"];
                t.Name = reader["Name"].ToString();
                t.ContactStatesString = reader["ContactStates"].ToString();
                t.StateAdminID = (short)reader["StateAdmin"];
                this.States.Add(t);
            }
            DbConnection.Close();
            foreach (State state in this.States)
            {
                state.LoadContactStatesFromString(this.States, state.ContactStatesString);
            }
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Region", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Region region = new Region();
                region.ID = (short)reader["ID"];
                region.Name = reader["Name"].ToString();
                region.LoadStatesFromString(this.States, reader["States"].ToString());
                region.RegionCoreID = (short)reader["RegionCore"];
                this.Regions.Add(region);
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Person", DbConnection).ExecuteReader();
            Dictionary<int, int> fatherIds = new Dictionary<int, int>();
            Dictionary<int, int> motherIds = new Dictionary<int, int>();
            Dictionary<int, int> spouseIds = new Dictionary<int, int>();
            Dictionary<int, int[]> brotherIds = new Dictionary<int, int[]>();
            Dictionary<int, int[]> closeIds = new Dictionary<int, int[]>();
            Dictionary<int, int[]> hatedIds = new Dictionary<int, int[]>();
            while (reader.Read())
            {
                Person person = new Person();
                person.Scenario = this;
                person.ID = (short)reader["ID"];
                person.PersonBiography = this.GameCommonData.AllBiographies.GetBiography(person.ID);
                person.Available = (bool)reader["Available"];
                person.Alive = (bool)reader["Alive"];
                person.SurName = reader["SurName"].ToString();
                person.GivenName = reader["GivenName"].ToString();
                person.CalledName = reader["CalledName"].ToString();
                person.Sex = (bool)reader["Sex"];
                person.PictureIndex = (short)reader["Pic"];
                person.Ideal = (short)reader["Ideal"];
                person.IdealTendency = this.GameCommonData.AllIdealTendencyKinds.GetGameObject((short)reader["IdealTendency"]) as IdealTendencyKind;
                person.LeaderPossibility = (bool)reader["LeaderPossibility"];
                person.Character = this.GameCommonData.AllCharacterKinds[(short)reader["PCharacter"]];
                person.YearAvailable = (short)reader["YearAvailable"];
                person.YearBorn = (short)reader["YearBorn"];
                person.YearDead = (short)reader["YearDead"];
                person.DeadReason = (PersonDeadReason)((short)reader["DeadReason"]);
                person.BaseStrength = (short)reader["Strength"];
                person.BaseCommand = (short)reader["Command"];
                person.BaseIntelligence = (short)reader["Intelligence"];
                person.BasePolitics = (short)reader["Politics"];
                person.BaseGlamour = (short)reader["Glamour"];
                person.Reputation = (int)reader["Reputation"];
                person.StrengthExperience = (int)reader["StrengthExperience"];
                person.CommandExperience = (int)reader["CommandExperience"];
                person.IntelligenceExperience = (int)reader["IntelligenceExperience"];
                person.PoliticsExperience = (int)reader["PoliticsExperience"];
                person.GlamourExperience = (int)reader["GlamourExperience"];
                person.InternalExperience = (int)reader["InternalExperience"];
                person.TacticsExperience = (int)reader["TacticsExperience"];
                person.BubingExperience = (int)reader["BubingExperience"];
                person.NubingExperience = (int)reader["NubingExperience"];
                person.QibingExperience = (int)reader["QibingExperience"];
                person.ShuijunExperience = (int)reader["ShuijunExperience"];
                person.QixieExperience = (int)reader["QixieExperience"];
                person.StratagemExperience = (int)reader["StratagemExperience"];
                person.RoutCount = (int)reader["RoutCount"];
                person.RoutedCount = (int)reader["RoutedCount"];
                person.Braveness = (short)reader["Braveness"];
                person.Calmness = (short)reader["Calmness"];
                person.Loyalty = (short)reader["Loyalty"];
                person.BornRegion = (PersonBornRegion)((short)reader["BornRegion"]);
                person.AvailableLocation = (short)reader["AvailableLocation"];
                person.Strain = (short)reader["Strain"];
                fatherIds[person.ID] = (short)reader["Father"];
                motherIds[person.ID] = (short)reader["Mother"];
                spouseIds[person.ID] = (short)reader["Spouse"];

                String str = reader["Brother"].ToString();
                char[] separator = new char[] { ' ', '\n', '\r', '\t' };
                string[] strArray = str.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                int[] intArray = new int[strArray.Length];
                for (int i = 0; i < strArray.Length; i++)
                {
                    intArray[i] = int.Parse(strArray[i]);
                }
                brotherIds.Add(person.ID, intArray);

                person.Generation = (short)reader["Generation"];
                person.PersonalLoyalty = ((short)reader["PersonalLoyalty"]);
                person.Ambition = ((short)reader["Ambition"]);
                person.Qualification = (PersonQualification)((short)reader["Qualification"]);
                person.ValuationOnGovernment = (PersonValuationOnGovernment)((short)reader["ValuationOnGovernment"]);
                person.StrategyTendency = (PersonStrategyTendency)((short)reader["StrategyTendency"]);
                person.OldFactionID = (short)reader["OldFactionID"];
                person.RewardFinished = (bool)reader["RewardFinished"];
                person.WorkKind = (ArchitectureWorkKind)((short)reader["WorkKind"]);
                person.OldWorkKind = (ArchitectureWorkKind)((short)reader["OldWorkKind"]);
                person.RecruitmentMilitary = null;
                person.ArrivingDays = (short)reader["ArrivingDays"];
                person.TaskDays = (short)reader["TaskDays"];
                person.OutsideTask = (OutsideTaskKind)((short)reader["OutsideTask"]);
                person.OutsideDestination = StaticMethods.LoadFromString(reader["OutsideDestination"].ToString());
                person.ConvincingPersonID = (short)reader["ConvincingPerson"];
                person.InformationKindID = (short)reader["InformationKind"];

                str = reader["ClosePersons"].ToString();
                strArray = str.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                intArray = new int[strArray.Length];
                for (int i = 0; i < strArray.Length; i++)
                {
                    intArray[i] = int.Parse(strArray[i]);
                }
                closeIds.Add(person.ID, intArray);

                str = reader["HatedPersons"].ToString();
                strArray = str.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                intArray = new int[strArray.Length];
                for (int i = 0; i < strArray.Length; i++)
                {
                    intArray[i] = int.Parse(strArray[i]);
                }
                hatedIds.Add(person.ID, intArray);

                person.Skills.LoadFromString(this.GameCommonData.AllSkills, reader["Skills"].ToString());

                try
                {
                    person.LoadTitleFromString(reader["Title"].ToString(), this.GameCommonData.AllTitles);
                }
                catch
                {
                    Title t = this.GameCommonData.AllTitles.GetTitle((short)reader["PersonalTitle"]);
                    if (t != null)
                    {
                        person.RealTitles.Add(t);
                    }
                    t = this.GameCommonData.AllTitles.GetTitle((short)reader["CombatTitle"]);
                    if (t != null)
                    {
                        person.RealTitles.Add(t);
                    }
                }

                person.StudyingTitle = this.GameCommonData.AllTitles.GetTitle((short)reader["StudyingTitle"]);
                person.huaiyun = (bool)reader["huaiyun"];
                person.faxianhuaiyun = (bool)reader["faxianhuaiyun"];
                person.huaiyuntianshu = short.Parse(reader["huaiyuntianshu"].ToString());

                try
                {
                    person.suoshurenwu = (short)reader["suoshurenwu"];
                }
                catch
                {

                }

                try
                {
                    person.Stunts.LoadFromString(this.GameCommonData.AllStunts, reader["Stunts"].ToString());
                    person.StudyingStunt = this.GameCommonData.AllStunts.GetStunt((short)reader["StudyingStunt"]);
                }
                catch
                {
                }

                try
                {
                    person.waitForFeiziId = int.Parse(reader["WaitForFeizi"].ToString());
                    person.WaitForFeiZiPeriod = (int)reader["WaitForFeiziPeriod"];
                }
                catch (Exception ex)
                {
                    person.waitForFeiziId = -1;
                    person.WaitForFeiZiPeriod = 0;
                }

                try
                {
                    person.preferredTroopPersonsString = reader["PreferredTroopPersons"].ToString();
                }
                catch (Exception ex)
                {
                    person.preferredTroopPersonsString = "";
                }

                try
                {
                    person.YearJoin = (short)reader["YearJoin"];
                    person.TroopDamageDealt = (int)reader["TroopDamageDealt"];
                    person.TroopBeDamageDealt = (int)reader["TroopBeDamageDealt"];
                    person.ArchitectureDamageDealt = (int)reader["ArchitectureDamageDealt"];
                    person.RebelCount = (short)reader["RebelCount"];
                    person.ExecuteCount = (short)reader["ExecuteCount"];
                    person.FleeCount = (short)reader["FleeCount"];
                    person.HeldCaptiveCount = (short)reader["HeldCaptiveCount"];
                    person.CaptiveCount = (short)reader["CaptiveCount"];
                    person.StratagemSuccessCount = (int)reader["StratagemSuccessCount"];
                    person.StratagemFailCount = (int)reader["StratagemFailCount"];
                    person.StratagemBeSuccessCount = (int)reader["StratagemBeSuccessCount"];
                    person.StratagemBeFailCount = (int)reader["StratagemBeFailCount"];
                }
                catch
                {
                    // all zeroes.
                }
                try
                {
                    person.Tiredness = (int)reader["Tiredness"];
                }
                catch
                {
                }
                try
                {
                    person.OfficerKillCount = (int)reader["OfficerKillCount"];
                }
                catch
                {
                }

                this.Persons.AddPersonWithEvent(person);  //所有武将,并加载武将事件
                this.AllPersons.Add(person.ID, person);   //武将字典
                if (person.Available && person.Alive)
                {
                    this.AvailablePersons.Add(person);  //已出场武将
                }
            }
            DbConnection.Close();
            foreach (Person p in this.Persons)
            {
                p.WaitForFeiZi = this.Persons.GetGameObject(p.waitForFeiziId) as Person;
                p.preferredTroopPersons.LoadFromString(this.Persons, p.preferredTroopPersonsString);
            }
            foreach (KeyValuePair<int, int> i in fatherIds)
            {
                (this.Persons.GetGameObject(i.Key) as Person).Father = this.Persons.GetGameObject(i.Value) as Person;
            }
            foreach (KeyValuePair<int, int> i in motherIds)
            {
                (this.Persons.GetGameObject(i.Key) as Person).Mother = this.Persons.GetGameObject(i.Value) as Person;
            }
            foreach (KeyValuePair<int, int> i in spouseIds)
            {
                (this.Persons.GetGameObject(i.Key) as Person).Spouse = this.Persons.GetGameObject(i.Value) as Person;
            }
            foreach (KeyValuePair<int, int[]> i in brotherIds)
            {
                if (i.Value.Length == 1 && i.Value[0] != -1)
                {
                    foreach (KeyValuePair<int, int[]> j in brotherIds)
                    {
                        if (j.Value.Length > 0 && i.Value[0] == j.Value[0])
                        {
                            Person p = this.Persons.GetGameObject(i.Key) as Person;
                            Person q = this.Persons.GetGameObject(j.Key) as Person;
                            p.Brothers.Add(q);
                        }
                    }
                }
                else
                {
                    Person p = this.Persons.GetGameObject(i.Key) as Person;
                    foreach (int j in i.Value)
                    {
                        Person q = this.Persons.GetGameObject(j) as Person;
                        if (q != null)
                        {
                            p.Brothers.Add(q);
                        }
                    }
                }
            }
            foreach (KeyValuePair<int, int[]> i in closeIds)
            {
                Person p = this.Persons.GetGameObject(i.Key) as Person;
                foreach (int j in i.Value)
                {
                    Person q = this.Persons.GetGameObject(j) as Person;
                    p.AddClose(q);
                }
            }
            foreach (KeyValuePair<int, int[]> i in hatedIds)
            {
                Person p = this.Persons.GetGameObject(i.Key) as Person;
                foreach (int j in i.Value)
                {
                    Person q = this.Persons.GetGameObject(j) as Person;
                    p.AddHated(q);
                }
            }
            DbConnection.Open();
            try
            {
                reader = new OleDbCommand("Select * From PersonRelation", DbConnection).ExecuteReader();
                while (reader.Read())
                {
                    Person person1 = this.Persons.GetGameObject((short)reader["Person1"]) as Person;
                    Person person2 = this.Persons.GetGameObject((short)reader["Person2"]) as Person;
                    int relation = (int)reader["Relation"];
                    person1.SetRelation(person2, relation);
                }
            }
            catch (OleDbException)
            {
                //ignore
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Captive", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Captive captive = new Captive();
                captive.Scenario = this;
                captive.ID = (short)reader["ID"];
                captive.CaptivePerson = this.Persons.GetGameObject((short)reader["CaptivePerson"]) as Person;
                captive.CaptivePerson.BelongedCaptive = captive;
                captive.CaptiveFactionID = (short)reader["CaptiveFaction"];
                captive.RansomArchitectureID = (short)reader["RansomArchitecture"];
                captive.RansomFund = (int)reader["RansomFund"];
                captive.RansomArriveDays = (int)reader["RansomArriveDays"];
                captive.CaptivePerson.Status = PersonStatus.Captive;
                if (!isInCaptiveList(captive.CaptivePerson.ID))
                {
                    this.Captives.AddCaptiveWithEvent(captive);
                }
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Military", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Military military = new Military();
                military.Scenario = this;
                military.ID = (short)reader["ID"];
                military.Name = reader["Name"].ToString();
                military.KindID = (short)reader["KindID"];
                military.Quantity = (int)reader["Quantity"];
                military.Morale = (int)reader["Morale"];
                military.Combativity = (int)reader["Combativity"];
                military.Experience = (int)reader["Experience"];
                military.InjuryQuantity = (int)reader["InjuryQuantity"];
                military.FollowedLeaderID = (short)reader["FollowedLeaderID"];
                military.LeaderID = (short)reader["LeaderID"];
                military.LeaderExperience = (int)reader["LeaderExperience"];
                int recruiter = (short)reader["RecruitmentPersonID"];
                foreach (Person p in this.Persons)
                {
                    if (p.ID == recruiter)
                    {
                        //p.RecruitmentMilitary = military;
                        p.RecruitMilitary(military);
                    }
                }
                military.ShelledMilitaryID = (short)reader["ShelledMilitary"];
                try
                {
                    military.Tiredness = (int)reader["Tiredness"];
                }
                catch
                {
                }
                if (military.Kind != null)
                {
                    this.Militaries.AddMilitary(military);
                }
            }
            this.InitializeMilitaryData();
            DbConnection.Close();

            DbConnection.Open();
            reader = new OleDbCommand("Select * From Facility", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Facility facility = new Facility();
                facility.Scenario = this;
                facility.ID = (short)reader["ID"];
                facility.KindID = (short)reader["KindID"];
                facility.Endurance = (int)reader["Endurance"];
                this.Facilities.AddFacility(facility);
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Information", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Information information = new Information();
                information.Scenario = this;
                information.ID = (short)reader["ID"];
                information.Level = (InformationLevel)((short)reader["iLevel"]);
                information.Position = new Point((short)reader["PositionX"], (short)reader["PositionY"]);
                information.Radius = (short)reader["Radius"];
                information.Oblique = (bool)reader["Oblique"];
                try
                {
                    information.DayCost = (int)reader["DayCost"];
                    information.DaysLeft = (int)reader["DaysLeft"];
                    information.DaysStarted = (int)reader["DaysStarted"];
                    this.Informations.AddInformation(information);
                }
                catch
                {
                }
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From SpyMessage", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                SpyMessage message = new SpyMessage();
                message.Scenario = this;
                message.ID = (int)reader["ID"];
                message.Kind = (SpyMessageKind)((short)reader["Kind"]);
                message.MessageFactionID = (short)reader["MessageFaction"];
                message.MessageArchitectureID = (short)reader["MessageArchitecture"];
                message.LoadPersonPacksFromString(this.AllPersons, reader["PersonPacks"].ToString());
                message.Message1 = reader["Message1"].ToString();
                message.Message2 = reader["Message2"].ToString();
                message.Message3 = reader["Message3"].ToString();
                message.Message4 = reader["Message4"].ToString();
                message.Message5 = reader["Message5"].ToString();
                this.SpyMessages.AddMessageWithEvent(message);
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Architecture", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Architecture architecture = new Architecture();
                architecture.Scenario = this;
                architecture.ID = (short)reader["ID"];
                try
                {
                    architecture.CaptionID = (short)reader["CaptionID"];
                }
                catch
                {
                    architecture.CaptionID = 9999;

                }
                architecture.Name = reader["Name"].ToString();
                architecture.Kind = this.GameCommonData.AllArchitectureKinds.GetArchitectureKind((short)reader["Kind"]);
                architecture.IsStrategicCenter = (bool)reader["IsStrategicCenter"];
                architecture.LocationState = this.States.GetGameObject((short)reader["StateID"]) as State;
                architecture.LocationState.Architectures.Add(architecture);
                architecture.LocationState.LinkedRegion.Architectures.Add(architecture);
                if (architecture.LocationState.StateAdminID == architecture.ID)
                {
                    architecture.LocationState.StateAdmin = architecture;
                }
                if (architecture.LocationState.LinkedRegion.RegionCoreID == architecture.ID)
                {
                    architecture.LocationState.LinkedRegion.RegionCore = architecture;
                }
                architecture.Characteristics.LoadFromString(this.GameCommonData.AllInfluences, reader["Characteristics"].ToString());
                architecture.LoadFromString(architecture.ArchitectureArea, reader["Area"].ToString());
                architecture.LoadPersonsFromString(this.AllPersons, reader["Persons"].ToString());
                architecture.LoadMovingPersonsFromString(this.AllPersons, reader["MovingPersons"].ToString());
                architecture.LoadNoFactionPersonsFromString(this.AllPersons, reader["NoFactionPersons"].ToString());
                architecture.LoadNoFactionMovingPersonsFromString(this.AllPersons, reader["NoFactionMovingPersons"].ToString());
                architecture.LoadfeiziPersonsFromString(this.AllPersons, reader["feiziliebiao"].ToString());
                architecture.Population = (int)reader["Population"];
                architecture.Fund = (int)reader["Fund"];
                architecture.Food = (int)reader["Food"];
                architecture.Agriculture = (int)reader["Agriculture"];
                architecture.Commerce = (int)reader["Commerce"];
                architecture.Technology = (int)reader["Technology"];
                architecture.Domination = (int)reader["Domination"];
                architecture.Morale = (int)reader["Morale"];
                architecture.Endurance = (int)reader["Endurance"];
                architecture.AutoHiring = (bool)reader["AutoHiring"];
                architecture.AutoRewarding = (bool)reader["AutoRewarding"];
                architecture.AutoWorking = (bool)reader["AutoWorking"];
                architecture.AutoSearching = (bool)reader["AutoSearching"];
                architecture.HireFinished = (bool)reader["HireFinished"];
                architecture.FacilityEnabled = (bool)reader["FacilityEnabled"];

                try
                {
                    architecture.MilitaryPopulation = (int)reader["MilitaryPopulation"];
                }
                catch
                {
                }

                architecture.LoadMilitariesFromString(this.Militaries, reader["Militaries"].ToString());
                architecture.LoadFacilitiesFromString(this.Facilities, reader["Facilities"].ToString());
                architecture.BuildingFacility = (int)reader["BuildingFacility"];
                architecture.BuildingDaysLeft = (int)reader["BuildingDaysLeft"];
                architecture.PlanFacilityKindID = (int)reader["PlanFacilityKind"];
                architecture.LoadFundPacksFromString(reader["FundPacks"].ToString());
                architecture.LoadSpyPacksFromString(reader["SpyPacks"].ToString());
                architecture.TodayNewMilitarySpyMessage = this.SpyMessages.GetGameObject((short)reader["TodayNewMilitarySpyMessage"]) as SpyMessage;
                architecture.TodayNewTroopSpyMessage = this.SpyMessages.GetGameObject((short)reader["TodayNewTroopSpyMessage"]) as SpyMessage;
                architecture.LoadPopulationPacksFromString(reader["PopulationPacks"].ToString());
                architecture.PlanArchitectureID = (int)reader["PlanArchitecture"];
                architecture.TransferFundArchitectureID = (int)reader["TransferFundArchitecture"];
                architecture.TransferFoodArchitectureID = (int)reader["TransferFoodArchitecture"];
                architecture.DefensiveLegionID = (int)reader["DefensiveLegion"];
                architecture.LoadCaptivesFromString(this.Captives, reader["Captives"].ToString());
                architecture.RobberTroopID = (short)reader["RobberTroop"];
                architecture.RecentlyAttacked = (short)reader["RecentlyAttacked"];
                architecture.RecentlyBreaked = (short)reader["RecentlyBreaked"];
                architecture.AILandLinksString = reader["AILandLinks"].ToString();
                architecture.AIWaterLinksString = reader["AIWaterLinks"].ToString();

                try
                {
                    architecture.youzainan = (bool)reader["youzainan"];
                    architecture.zainan.zainanzhonglei = this.GameCommonData.suoyouzainanzhonglei.Getzainanzhonglei((short)reader["zainanleixing"]);
                    architecture.zainan.shengyutianshu = (short)reader["zainanshengyutianshu"];
                }
                catch
                {
                    architecture.youzainan = false;

                }
                try
                {
                    architecture.huangdisuozai = (bool)reader["Emperor"];
                }
                catch
                {
                    architecture.huangdisuozai = false;

                }

                try
                {

                    architecture.LoadInformationsFromString(this.Informations, (string)reader["Informations"]);
                }
                catch
                {
                }

                this.Architectures.AddArchitectureWithEvent(architecture);
                this.AllArchitectures.Add(architecture.ID, architecture);
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Routeway", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Routeway routeway = new Routeway();
                routeway.Scenario = this;
                routeway.ID = (short)reader["ID"];
                routeway.Building = (bool)reader["Building"];
                routeway.ShowArea = (bool)reader["ShowArea"];
                routeway.RemoveAfterClose = (bool)reader["RemoveAfterClose"];
                routeway.LastActivePointIndex = (int)reader["LastActivePointIndex"];
                routeway.InefficiencyDays = (int)reader["InefficiencyDays"];
                routeway.StartArchitecture = this.Architectures.GetGameObject((int)reader["StartArchitecture"]) as Architecture;
                if (routeway.StartArchitecture != null)
                {
                    routeway.StartArchitecture.Routeways.Add(routeway);
                }
                routeway.EndArchitecture = this.Architectures.GetGameObject((int)reader["EndArchitecture"]) as Architecture;
                routeway.DestinationArchitecture = this.Architectures.GetGameObject((int)reader["DestinationArchitecture"]) as Architecture;
                routeway.LoadRoutePointsFromString(reader["Points"].ToString());
                this.Routeways.AddRoutewayWithEvent(routeway);
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Troop", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Troop troop = new Troop();
                troop.Scenario = this;
                troop.ID = (short)reader["ID"];
                troop.Controllable = (bool)reader["Controllable"];
                troop.SetStatus((TroopStatus)((short)reader["Status"]));
                troop.Direction = (TroopDirection)((short)reader["Direction"]);
                troop.Auto = (bool)reader["Auto"];
                troop.Operated = (bool)reader["Operated"];
                troop.Food = (int)reader["Food"];
                troop.zijin = (int)reader["zijin"];
                troop.StartingArchitecture = this.Architectures.GetGameObject((short)reader["StartingArchitecture"]) as Architecture;
                troop.LoadPersonsFromString(this.AllPersons, reader["Persons"].ToString(), (short)reader["LeaderID"]);
                troop.LoadPathInformation((short)reader["PositionX"], (short)reader["PositionY"], (short)reader["DestinationX"], (short)reader["DestinationY"], (short)reader["RealDestinationX"], (short)reader["RealDestinationY"], reader["FirstTierPath"].ToString(), reader["SecondTierPath"].ToString(), reader["ThirdTierPath"].ToString(), (short)reader["FirstIndex"], (short)reader["SecondIndex"], (short)reader["ThirdIndex"]);
                troop.MilitaryID = (short)reader["MilitaryID"];
                troop.AttackDefaultKind = (TroopAttackDefaultKind)((short)reader["AttackDefaultKind"]);
                troop.AttackTargetKind = (TroopAttackTargetKind)((short)reader["AttackTargetKind"]);
                troop.TargetTroopID = (short)reader["TargetTroopID"];
                troop.TargetArchitectureID = (short)reader["TargetArchitectureID"];
                troop.WillTroopID = (short)reader["WillTroopID"];
                troop.WillArchitectureID = (short)reader["WillArchitectureID"];
                troop.CurrentCombatMethodID = (short)reader["CurrentCombatMethodID"];
                troop.CurrentStratagemID = (short)reader["CurrentStratagemID"];
                troop.SelfCastPosition = new Point((short)reader["SelfCastPositionX"], (short)reader["SelfCastPositionY"]);
                troop.ChaosDayLeft = (short)reader["ChaosDayLeft"];
                troop.CutRoutewayDays = (short)reader["CutRoutewayDays"];
                troop.LoadCaptivesFromString(this.Captives, reader["Captives"].ToString());
                troop.RecentlyFighting = (short)reader["RecentlyFighting"];
                troop.TechnologyIncrement = (short)reader["TechnologyIncrement"];
                troop.EventInfluences.LoadFromString(this.GameCommonData.AllInfluences, reader["EventInfluences"].ToString());
                try
                {
                    troop.CurrentStunt = this.GameCommonData.AllStunts.GetStunt((short)reader["CurrentStunt"]);
                    troop.StuntDayLeft = (short)reader["StuntDayLeft"];
                }
                catch
                {
                }
                try
                {
                    troop.mingling = reader["mingling"].ToString();
                }
                catch
                {
                }
                try
                {
                    troop.ManualControl = (bool)reader["ManualControl"];
                }
                catch
                {
                }
                troop.minglingweizhi = troop.RealDestination;
                if (troop.Army != null)
                {
                    this.Troops.AddTroopWithEvent(troop);
                }
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Legion", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Legion legion = new Legion();
                legion.Scenario = this;
                legion.ID = int.Parse(reader["ID"].ToString());
                legion.Kind = (LegionKind)((short)reader["Kind"]);
                legion.StartArchitecture = this.Architectures.GetGameObject((int)reader["StartArchitecture"]) as Architecture;
                legion.WillArchitecture = this.Architectures.GetGameObject((int)reader["WillArchitecture"]) as Architecture;
                legion.PreferredRouteway = this.Routeways.GetGameObject((int)reader["PreferredRouteway"]) as Routeway;
                legion.InformationDestination = StaticMethods.LoadFromString(reader["InformationDestination"].ToString());
                legion.CoreTroop = this.Troops.GetGameObject((int)reader["CoreTroop"]) as Troop;
                legion.LoadTroopsFromString(this.Troops, reader["Troops"].ToString());
                this.Legions.AddLegionWithEvent(legion);
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Sections", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Section section = new Section();
                section.Scenario = this;
                section.ID = int.Parse(reader["ID"].ToString());
                section.Name = reader["Name"].ToString();
                section.AIDetail = this.GameCommonData.AllSectionAIDetails.GetSectionAIDetail((short)reader["AIDetail"]);
                section.OrientationFactionID = (short)reader["OrientationFaction"];
                section.OrientationSectionID = (short)reader["OrientationSection"];
                section.OrientationStateID = (short)reader["OrientationState"];
                try
                {
                    section.OrientationArchitectureID = (short)reader["OrientationArchitecture"];
                }
                catch
                {
                }
                section.LoadArchitecturesFromString(this.Architectures, reader["Architectures"].ToString());
                this.Sections.AddSectionWithEvent(section);
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From Faction", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                Faction faction = new Faction();
                faction.Scenario = this;
                faction.ID = (short)reader["ID"];
                faction.Passed = (bool)reader["Passed"];
                faction.PreUserControlFinished = (bool)reader["PreUserControlFinished"];
                faction.Controlling = (bool)reader["Controlling"];
                faction.LeaderID = (short)reader["LeaderID"];
                faction.ColorIndex = (short)reader["ColorIndex"];
                faction.FactionColor = this.GameCommonData.AllColors[faction.ColorIndex];
                faction.Name = reader["FName"].ToString();
                faction.CapitalID = (short)reader["CapitalID"];
                faction.Reputation = (int)reader["Reputation"];
                faction.TechniquePoint = (int)reader["TechniquePoint"];
                faction.TechniquePointForTechnique = (int)reader["TechniquePointForTechnique"];
                faction.TechniquePointForFacility = (int)reader["TechniquePointForFacility"];
                faction.LoadArchitecturesFromString(this.Architectures, reader["Architectures"].ToString());
                faction.LoadTroopsFromString(this.Troops, reader["Troops"].ToString());
                faction.LoadInformationsFromString(this.Informations, reader["Informations"].ToString());
                faction.LoadRoutewaysFromString(this.Routeways, reader["Routeways"].ToString());
                faction.LoadLegionsFromString(this.Legions, reader["Legions"].ToString());
                faction.LoadSectionsFromString(this.Sections, reader["Sections"].ToString());
                faction.BaseMilitaryKinds.LoadFromString(this.GameCommonData.AllMilitaryKinds, reader["BaseMilitaryKinds"].ToString());
                faction.UpgradingTechnique = (short)reader["UpgradingTechnique"];
                faction.UpgradingDaysLeft = (short)reader["UpgradingDaysLeft"];
                faction.AvailableTechniques.LoadFromString(this.GameCommonData.AllTechniques, reader["AvailableTechniques"].ToString());
                StaticMethods.LoadFromString(faction.PreferredTechniqueKinds, reader["PreferredTechniqueKinds"].ToString());
                faction.PlanTechnique = this.GameCommonData.AllTechniques.GetTechnique((short)reader["PlanTechnique"]);
                faction.AutoRefuse = (bool)reader["AutoRefuse"];
                try
                {
                    faction.chaotinggongxiandu = (int)reader["chaotinggongxiandu"];
                }
                catch
                {
                    faction.chaotinggongxiandu = 0;

                }
                try
                {
                    faction.guanjue = (short)reader["guanjue"];
                }
                catch
                {
                    faction.guanjue = 0;

                }
                try
                {
                    faction.IsAlien = (bool)reader["IsAlien"];
                }
                catch
                {
                    faction.IsAlien = false;
                }
                if (faction.AvailableMilitaryKinds.GetMilitaryKindList().Count == 0)
                {
                    faction.AvailableMilitaryKinds.AddMilitaryKind(this.GameCommonData.AllMilitaryKinds.GetMilitaryKind(0));
                    faction.AvailableMilitaryKinds.AddMilitaryKind(this.GameCommonData.AllMilitaryKinds.GetMilitaryKind(1));
                    faction.AvailableMilitaryKinds.AddMilitaryKind(this.GameCommonData.AllMilitaryKinds.GetMilitaryKind(2));
                }
                this.Factions.AddFactionWithEvent(faction);
            }
            DbConnection.Close();
            DbConnection.Open();
            try
            {
                reader = new OleDbCommand("Select * From Treasure", DbConnection).ExecuteReader();
                while (reader.Read())
                {
                    Treasure treasure = new Treasure();
                    treasure.Scenario = this;
                    treasure.ID = (short)reader["ID"];
                    treasure.Name = reader["Name"].ToString();
                    treasure.Description = reader["Description"].ToString();
                    treasure.Pic = (short)reader["Pic"];
                    treasure.Worth = (short)reader["Worth"];
                    treasure.Available = (bool)reader["Available"];
                    treasure.AppearYear = (short)reader["AppearYear"];
                    try
                    {
                        treasure.TreasureGroup = (short)reader["TreasureGroup"];
                    }
                    catch
                    {
                        treasure.TreasureGroup = treasure.ID;
                    }
                    int key = (short)reader["HidePlace"];
                    treasure.HidePlace = this.AllArchitectures.ContainsKey(key) ? this.AllArchitectures[key] : null;
                    int num2 = (short)reader["BelongedPerson"];
                    treasure.BelongedPerson = this.AllPersons.ContainsKey(num2) ? this.AllPersons[num2] : null;
                    if (treasure.BelongedPerson != null)
                    {
                        treasure.BelongedPerson.Treasures.Add(treasure);
                    }
                    treasure.Influences.LoadFromString(this.GameCommonData.AllInfluences, reader["Influences"].ToString());
                    this.Treasures.AddTreasure(treasure);
                }
            }
            catch
            {
            }
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From DiplomaticRelation", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                DiplomaticRelation dr = new DiplomaticRelation();
                dr.Scenario = this;
                dr.RelationFaction1ID = (short)reader["Faction1ID"];
                dr.RelationFaction2ID = (short)reader["Faction2ID"];
                dr.Relation = (int)reader["Relation"];
                try
                {
                    dr.Truce = (int)reader["Truce"];
                }
                catch
                {
                }
                this.DiplomaticRelations.AddDiplomaticRelation(dr);
            }
            DbConnection.Close();
            command = new OleDbCommand("Select * From GameSurvey", DbConnection);
            DbConnection.Open();
            reader = command.ExecuteReader();
            reader.Read();
            this.ScenarioTitle = reader["Title"].ToString();
            this.ScenarioDescription = reader["Description"].ToString();
            this.Date.LoadDateData((short)reader["GYear"], (short)reader["GMonth"], (short)reader["GDay"]);
            this.ScenarioMap.JumpPosition = StaticMethods.LoadFromString(reader["JumpPosition"].ToString()).Value;
            DbConnection.Close();
            DbConnection.Open();
            reader = new OleDbCommand("Select * From TroopEvent", DbConnection).ExecuteReader();
            while (reader.Read())
            {
                TroopEvent te = new TroopEvent();
                te.Scenario = this;
                te.ID = (short)reader["ID"];
                te.Name = reader["Name"].ToString();
                te.Happened = (bool)reader["Happened"];
                te.Repeatable = (bool)reader["Repeatable"];
                try
                {
                    te.AfterEventHappened = (short)reader["AfterEventHappened"];
                }
                catch
                {
                }
                te.LaunchPerson = this.Persons.GetGameObject((short)reader["LaunchPerson"]) as Person;
                te.Conditions.LoadFromString(this.GameCommonData.AllConditions, reader["Conditions"].ToString());
                te.HappenChance = (short)reader["Chance"];
                te.CheckArea = (EventCheckAreaKind)((short)reader["CheckAreaKind"]);
                te.LoadTargetPersonFromString(this.AllPersons, reader["TargetPersons"].ToString());
                te.LoadDialogFromString(this.AllPersons, reader["Dialogs"].ToString());
                te.LoadSelfEffectFromString(this.GameCommonData.AllTroopEventEffects, reader["EffectSelf"].ToString());
                te.LoadEffectPersonFromString(this.AllPersons, this.GameCommonData.AllTroopEventEffects, reader["EffectPersons"].ToString());
                te.LoadEffectAreaFromString(this.GameCommonData.AllTroopEventEffects, reader["EffectAreas"].ToString());
                this.TroopEvents.AddTroopEventWithEvent(te);
            }
            DbConnection.Close();
            try
            {
                DbConnection.Open();
                reader = new OleDbCommand("Select * From Event", DbConnection).ExecuteReader();

                while (reader.Read())
                {
                    try
                    {
                        Event e = new Event();
                        e.Scenario = this;
                        e.ID = (short)reader["ID"];
                        e.Name = reader["Name"].ToString();
                        e.repeatable = (bool)reader["Repeatable"];
                        e.AfterEventHappened = (short)reader["AfterEventHappened"];
                        e.happenChance = (short)reader["Chance"];
                        e.LoadPersonIdFromString(this.Persons, reader["PersonId"].ToString());
                        e.LoadPersonCondFromString(this.GameCommonData.AllConditions, reader["PersonCond"].ToString());
                        e.LoadArchitectureFromString(this.Architectures, reader["ArchitectureID"].ToString());
                        e.LoadArchitctureCondFromString(this.GameCommonData.AllConditions, reader["ArchitectureCond"].ToString());
                        e.LoadFactionFromString(this.Factions, reader["FactionID"].ToString());
                        e.LoadFactionCondFromString(this.GameCommonData.AllConditions, reader["FactionCond"].ToString());
                        e.LoadDialogFromString(reader["Dialog"].ToString());
                        e.LoadEffectFromString(this.GameCommonData.AllEventEffects, reader["Effect"].ToString());
                        e.LoadArchitectureEffectFromString(this.GameCommonData.AllEventEffects, reader["ArchitectureEffect"].ToString());
                        e.LoadFactionEffectFromString(this.GameCommonData.AllEventEffects, reader["FactionEffect"].ToString());
                        this.AllEvents.AddEventWithEvent(e);
                    }
                    catch
                    {
                        //ignore this event
                    }
                }
            }
            catch
            {
                //ignore, let there be empty event list
            }
            finally
            {
                DbConnection.Close();
            }
            try
            {
                DbConnection.Open();
                reader = new OleDbCommand("Select * From YearTable", DbConnection).ExecuteReader();
                while (reader.Read())
                {
                    int id = (int)reader["ID"];
                    int year = (short)reader["GYear"];
                    int month = (short)reader["GMonth"];
                    int day = (short)reader["GDay"];
                    FactionList faction = new FactionList();
                    faction.LoadFromString(this.Factions, (string)reader["Faction"]);
                    string content = (string)reader["Content"];
                    bool isGlobal = (bool)reader["IsGloballyKnown"];
                    this.YearTable.addTableEntry(id, new GameDate(year, month, day), faction, content, isGlobal);
                }
            }
            catch
            {
                //ignore, let there be empty yeartable
            }
            finally
            {
                DbConnection.Close();
            }
            /*try
            {
                DbConnection.Open();
                reader = new OleDbCommand("Select * From AAPaths", DbConnection).ExecuteReader();
                while (reader.Read())
                {
                    int aid1 = (short)reader["Architecture1"];
                    int aid2 = (short)reader["Architecture2"];
                    if (aid1 == aid2) continue;
                    int kid = (short)reader["MilitaryKind"];
                    Architecture a1 = this.Architectures.GetGameObject(aid1) as Architecture;
                    Architecture a2 = this.Architectures.GetGameObject(aid2) as Architecture;
                    MilitaryKind mk = this.GameCommonData.AllMilitaryKinds.GetMilitaryKind(kid);
                    List<Point> path = new List<Point>();
                    StaticMethods.LoadFromString(path, (string)reader["Path"]);
                    this.pathCache[new PathCacheKey(a1, a2, mk)] = path;
                }
            }
            catch
            {
                //ignore, let there be empty cache
            }
            finally
            {
                DbConnection.Close();
            }*/
            this.AllPersons.Clear();
            this.AllArchitectures.Clear();

            this.alterTransportShipAdaptibility();

            ExtensionInterface.call("Load", new Object[] { this });
        }