public override void OnResponseReceived( dynamic data ) {

			KCDatabase db = KCDatabase.Instance;


			//api_ship_data
			foreach ( var elem in data.api_ship_data ) {

				int id = (int)elem.api_id;
				ShipData ship = db.Ships[id];

				if ( ship != null ) {
					ship.LoadFromResponse( APIName, elem );

				} else {	//ないとは思うけど
					var a = new ShipData();
					a.LoadFromResponse( APIName, elem );
					db.Ships.Add( a );

				}

			}


			//api_deck_data
			db.Fleet.LoadFromResponse( APIName, data.api_deck_data );

			base.OnResponseReceived( (object)data );
		}
		public override void OnResponseReceived( dynamic data ) {

			KCDatabase db = KCDatabase.Instance;

			int setid = (int)data.api_ship_data.api_set_ship.api_id;
			int unsetid = (int)data.api_ship_data.api_unset_ship.api_id;

			// 念のため
			if ( !db.Ships.ContainsKey( setid ) ) {
				var a = new ShipData();
				a.LoadFromResponse( APIName, data.api_ship_data.api_set_ship );
				db.Ships.Add( a );

			} else {
				db.Ships[setid].LoadFromResponse( APIName, data.api_ship_data.api_set_ship );
			}


			if ( !db.Ships.ContainsKey( unsetid ) ) {
				var a = new ShipData();
				a.LoadFromResponse( APIName, data.api_ship_data.api_unset_ship );
				db.Ships.Add( a );

			} else {
				db.Ships[unsetid].LoadFromResponse( APIName, data.api_ship_data.api_unset_ship );
			}

			base.OnResponseReceived( (object)data );
		}
		public override void OnResponseReceived( dynamic data ) {

			KCDatabase db = KCDatabase.Instance;

			var ship = db.Ships[(int)data.api_ship.api_id];
			

			if ( ship != null ) {

				if ( Utility.Configuration.Config.Log.ShowSpoiler ) {
					if ( (int)data.api_powerup_flag == 0 ) {
						Utility.Logger.Add( 2, ship.NameWithLevel + " の近代化改修に失敗しました。" );

					} else {
						var updated_ship = new ShipData();
						updated_ship.LoadFromResponse( APIName, data.api_ship );

						StringBuilder sb = new StringBuilder();
						sb.Append( ship.NameWithLevel + " の近代化改修に成功しました。( " );

						var contents = new LinkedList<string>();

						int firepower = updated_ship.FirepowerBase - ship.FirepowerBase;
						if ( firepower > 0 )
							contents.AddLast( "火力+" + firepower );
						int torpedo = updated_ship.TorpedoBase - ship.TorpedoBase;
						if ( torpedo > 0 )
							contents.AddLast( "雷装+" + torpedo );
						int aa = updated_ship.AABase - ship.AABase;
						if ( aa > 0 )
							contents.AddLast( "対空+" + aa );
						int armor = updated_ship.ArmorBase - ship.ArmorBase;
						if ( armor > 0 )
							contents.AddLast( "装甲+" + armor );
						int luck = updated_ship.LuckBase - ship.LuckBase;
						if ( luck > 0 )
							contents.AddLast( "運+" + luck );

						sb.AppendFormat( string.Join( ", ", contents ) + " )" );
						Utility.Logger.Add( 2, sb.ToString() );
					}
				}
				ship.LoadFromResponse( APIName, data.api_ship );
			}

			db.Fleet.LoadFromResponse( APIName, data.api_deck );


			base.OnResponseReceived( (object)data );
		}
		public override void OnResponseReceived( dynamic data ) {

			KCDatabase db = KCDatabase.Instance;


			//api_material
			db.Material.LoadFromResponse( APIName, data.api_material );

			//api_basic
			db.Admiral.LoadFromResponse( APIName, data.api_basic );

			//api_ship
			db.Ships.Clear();
			foreach ( var elem in data.api_ship ) {

				var a = new ShipData();
				a.LoadFromResponse( APIName, elem );
				db.Ships.Add( a );

			}


			//api_ndock
			foreach ( var elem in data.api_ndock ) {

				int id = (int)elem.api_id;

				if ( !db.Docks.ContainsKey( id ) ) {
					var a = new DockData();
					a.LoadFromResponse( APIName, elem );
					db.Docks.Add( a );

				} else {
					db.Docks[id].LoadFromResponse( APIName, elem );
				}
			}

			//api_deck_port
			db.Fleet.LoadFromResponse( APIName, data.api_deck_port );
			db.Fleet.CombinedFlag = data.api_combined_flag() ? (int)data.api_combined_flag : 0;


			db.Battle.LoadFromResponse( APIName, data );

			base.OnResponseReceived( (object)data );
		}
		public override void OnResponseReceived( dynamic data ) {

			KCDatabase db = KCDatabase.Instance;

			//api_kdock
			foreach ( var ars in data.api_kdock ) {

				int id = (int)ars.api_id;

				if ( !db.Arsenals.ContainsKey( id ) ) {
					var a = new ArsenalData();
					a.LoadFromResponse( APIName, ars );
					db.Arsenals.Add( a );

				} else {
					db.Arsenals[id].LoadFromResponse( APIName, ars );
				}
			}

			//api_slotitem
			if ( data.api_slotitem != null ) {				//装備なしの艦はnullになる
				foreach ( var elem in data.api_slotitem ) {

					var eq = new EquipmentData();
					eq.LoadFromResponse( APIName, elem );
					db.Equipments.Add( eq );

				}
			}

			//api_ship
			{
				ShipData ship = new ShipData();
				ship.LoadFromResponse( APIName, data.api_ship );
				db.Ships.Add( ship );

				Utility.Logger.Add( 2, string.Format( "{0}「{1}」の建造が完了しました。", ship.MasterShip.ShipTypeName, ship.MasterShip.NameWithClass ) );
			}


			base.OnResponseReceived( (object)data );
		}
        /// <summary>
        /// 対潜攻撃可能であるかを取得します。
        /// </summary>
        /// <param name="ship">対象の艦船データ。</param>
        public static bool CanAttackSubmarine( ShipData ship )
        {
            switch ( ship.MasterShip.ShipType ) {
                case 2:		//駆逐
                case 3:		//軽巡
                case 4:		//雷巡
                case 21:	//練巡
                case 22:	//補給
                    return ship.ASWBase > 0;

                case 6:		//航巡
                case 7:		//軽空母
                case 10:	//航戦
                case 16:	//水母
                case 17:	//揚陸
                    return ship.SlotInstanceMaster.Count( eq => eq != null && IsAircraft( eq.EquipmentID, false ) && eq.ASW > 0 ) > 0;

                default:
                    return false;
            }
        }
		public override void OnResponseReceived( dynamic data ) {

			KCDatabase db = KCDatabase.Instance;


			//api_data
			db.Ships.Clear();
			foreach ( var elem in data.api_data ) {

				var a = new ShipData();
				a.LoadFromResponse( APIName, elem );
				db.Ships.Add( a );

			}
			

			//api_data_deck
			db.Fleet.LoadFromResponse( APIName, data.api_data_deck );

			base.OnResponseReceived( (object)data );
		}
        /// <summary>
        /// 制空戦力を求めます。
        /// </summary>
        /// <param name="ship">対象の艦船。</param>
        public static int GetAirSuperiority( ShipData ship )
        {
            if ( ship == null ) return 0;

            if ( Utility.Configuration.Config.FormFleet.AirSuperiorityMethod == 0 ) {
                return GetAirSuperiority( ship.SlotMaster.ToArray(), ship.Aircraft.ToArray() );
            }

            int air = 0;
            var eqs = ship.SlotInstance;
            var aircrafts = ship.Aircraft;

            for ( int i = 0; i < eqs.Count; i++ ) {
                var eq = eqs[i];
                if ( eq != null && aircrafts[i] > 0 ) {

                    int category = eq.MasterEquipment.CategoryType;

                    if ( AircraftLevelBonus.ContainsKey( category ) ) {

                        double levelRate;
                        switch ( category ) {
                            case 6:		// 艦上戦闘機
                                levelRate = 0.2;
                                break;
                            case 7:		// 艦上爆撃機
                                levelRate = 0.25;
                                break;
                            default:
                                levelRate = 0;
                                break;
                        }

                        air += (int)( ( eq.MasterEquipment.AA + levelRate * eq.Level ) * Math.Sqrt( aircrafts[i] ) + Math.Sqrt( AircraftExpTable[eq.AircraftLevel] / 10.0 ) + AircraftLevelBonus[category][eq.AircraftLevel] );
                    }

                }
            }

            return air;
        }
 /// <summary>
 /// パラメータを更新します。
 /// </summary>
 /// <param name="ship">対象の艦船。</param>
 public void UpdateParameter( ShipData ship )
 {
     UpdateParameter( ship.ShipID, ship.Level, ship.ASWBase, ship.ASWMax, ship.EvasionBase, ship.EvasionMax, ship.LOSBase, ship.LOSMax );
 }
        /// <summary>
        /// 初期装備を更新します。
        /// </summary>
        /// <param name="ship">対象の艦船。入手直後・改装直後のものに限ります。</param>
        public void UpdateDefaultSlot( ShipData ship )
        {
            int[] slot = new int[ship.Slot.Count];

            for ( int i = 0; i < slot.Length; i++ ) {
                if ( ship.Slot[i] == -1 )
                    slot[i] = -1;
                else
                    slot[i] = KCDatabase.Instance.Equipments[ship.Slot[i]].EquipmentID;
            }

            UpdateDefaultSlot( ship.ShipID, slot );
        }
        private string GetEquipmentOnlyString( ShipData ship, int index )
        {
            string name = ship.SlotInstance[index] != null ? ship.SlotInstance[index].NameWithLevel : GeneralRes.None;

            if ( index >= ship.MasterShip.SlotSize && ship.Slot[index] == -1 ) {
                return "";

            } else {
                return name;

            }
        }
        /// <summary>
        /// ShipView用の新しい行のインスタンスを作成します。
        /// </summary>
        /// <param name="ship">追加する艦娘データ。</param>
        private DataGridViewRow CreateShipViewRow( ShipData ship )
        {
            if ( ship == null ) return null;

            DataGridViewRow row = new DataGridViewRow();
            row.CreateCells( ShipView );

            row.SetValues(
                ship.MasterID,
                ship.MasterShip.ShipType,
                ship.MasterShip.Name,
                ship.Level,
                ship.ExpTotal,
                ship.ExpNext,
                ship.ExpNextRemodel,
                new Fraction( ship.HPCurrent, ship.HPMax ),
                ship.Condition,
                new Fraction( ship.Fuel, ship.FuelMax ),
                new Fraction( ship.Ammo, ship.AmmoMax ),
                GetEquipmentString( ship, 0 ),
                GetEquipmentString( ship, 1 ),
                GetEquipmentString( ship, 2 ),
                GetEquipmentString( ship, 3 ),
                GetEquipmentString( ship, 4 ),
                GetEquipmentString( ship, 5 ),		//補強スロット
                new Fraction( ship.Aircraft[0], ship.MasterShip.Aircraft[0] ),
                new Fraction( ship.Aircraft[1], ship.MasterShip.Aircraft[1] ),
                new Fraction( ship.Aircraft[2], ship.MasterShip.Aircraft[2] ),
                new Fraction( ship.Aircraft[3], ship.MasterShip.Aircraft[3] ),
                new Fraction( ship.Aircraft[4], ship.MasterShip.Aircraft[4] ),
                new Fraction( ship.AircraftTotal, ship.MasterShip.AircraftTotal ),
                ship.FleetWithIndex,
                ship.RepairingDockID == -1 ? ship.RepairTime : -1000 + ship.RepairingDockID,
                ship.RepairSteel,
                ship.RepairFuel,
                ship.FirepowerBase,
                ship.FirepowerRemain,
                ship.FirepowerTotal,
                ship.TorpedoBase,
                ship.TorpedoRemain,
                ship.TorpedoTotal,
                ship.AABase,
                ship.AARemain,
                ship.AATotal,
                ship.ArmorBase,
                ship.ArmorRemain,
                ship.ArmorTotal,
                ship.ASWBase,
                ship.ASWTotal,
                ship.EvasionBase,
                ship.EvasionTotal,
                ship.LOSBase,
                ship.LOSTotal,
                ship.LuckBase,
                ship.LuckRemain,
                ship.LuckTotal,
                ship.BomberTotal,
                ship.MasterShip.Speed,
                ship.Range,
                ship.AirBattlePower,
                ship.ShellingPower,
                ship.AircraftPower,
                ship.AntiSubmarinePower,
                ship.TorpedoPower,
                ship.NightBattlePower,
                ship.IsLocked ? 1 : ship.IsLockedByEquipment ? 2 : 0,
                ship.SallyArea
                );

            row.Cells[ShipView_Name.Index].Tag = ship.ShipID;
            //row.Cells[ShipView_Level.Index].Tag = ship.ExpTotal;

            {
                DataGridViewCellStyle cs;
                double hprate = ship.HPRate;
                if ( hprate <= 0.25 )
                    cs = CSRedRight;
                else if ( hprate <= 0.50 )
                    cs = CSOrangeRight;
                else if ( hprate <= 0.75 )
                    cs = CSYellowRight;
                else if ( hprate < 1.00 )
                    cs = CSGreenRight;
                else
                    cs = CSDefaultRight;

                row.Cells[ShipView_HP.Index].Style = cs;
            }
            {
                DataGridViewCellStyle cs;
                if ( ship.Condition < 20 )
                    cs = CSRedRight;
                else if ( ship.Condition < 30 )
                    cs = CSOrangeRight;
                else if ( ship.Condition < Utility.Configuration.Config.Control.ConditionBorder )
                    cs = CSYellowRight;
                else if ( ship.Condition < 50 )
                    cs = CSDefaultRight;
                else
                    cs = CSGreenRight;

                row.Cells[ShipView_Condition.Index].Style = cs;
            }
            row.Cells[ShipView_Fuel.Index].Style = ship.Fuel < ship.FuelMax ? CSYellowRight : CSDefaultRight;
            row.Cells[ShipView_Ammo.Index].Style = ship.Ammo < ship.AmmoMax ? CSYellowRight : CSDefaultRight;
            {
                var current = ship.Aircraft;
                var max = ship.MasterShip.Aircraft;
                row.Cells[ShipView_Aircraft1.Index].Style = ( max[0] > 0 && current[0] == 0 ) ? CSRedRight : ( current[0] < max[0] ) ? CSYellowRight : CSDefaultRight;
                row.Cells[ShipView_Aircraft2.Index].Style = ( max[1] > 0 && current[1] == 0 ) ? CSRedRight : ( current[1] < max[1] ) ? CSYellowRight : CSDefaultRight;
                row.Cells[ShipView_Aircraft3.Index].Style = ( max[2] > 0 && current[2] == 0 ) ? CSRedRight : ( current[2] < max[2] ) ? CSYellowRight : CSDefaultRight;
                row.Cells[ShipView_Aircraft4.Index].Style = ( max[3] > 0 && current[3] == 0 ) ? CSRedRight : ( current[3] < max[3] ) ? CSYellowRight : CSDefaultRight;
                row.Cells[ShipView_Aircraft5.Index].Style = ( max[4] > 0 && current[4] == 0 ) ? CSRedRight : ( current[4] < max[4] ) ? CSYellowRight : CSDefaultRight;
                row.Cells[ShipView_AircraftTotal.Index].Style = ( ship.MasterShip.AircraftTotal > 0 && ship.AircraftTotal == 0 ) ? CSRedRight : ( ship.AircraftTotal < ship.MasterShip.AircraftTotal ) ? CSYellowRight : CSDefaultRight;
            }
            {
                DataGridViewCellStyle cs;
                if ( ship.RepairTime == 0 )
                    cs = CSDefaultRight;
                else if ( ship.RepairTime < 1000 * 60 * 60 )
                    cs = CSYellowRight;
                else if ( ship.RepairTime < 1000 * 60 * 60 * 6 )
                    cs = CSOrangeRight;
                else
                    cs = CSRedRight;

                row.Cells[ShipView_RepairTime.Index].Style = cs;
            }
            row.Cells[ShipView_FirepowerRemain.Index].Style = ship.FirepowerRemain == 0 ? CSGrayRight : CSDefaultRight;
            row.Cells[ShipView_TorpedoRemain.Index].Style = ship.TorpedoRemain == 0 ? CSGrayRight : CSDefaultRight;
            row.Cells[ShipView_AARemain.Index].Style = ship.AARemain == 0 ? CSGrayRight : CSDefaultRight;
            row.Cells[ShipView_ArmorRemain.Index].Style = ship.ArmorRemain == 0 ? CSGrayRight : CSDefaultRight;
            row.Cells[ShipView_LuckRemain.Index].Style = ship.LuckRemain == 0 ? CSGrayRight : CSDefaultRight;

            row.Cells[ShipView_Locked.Index].Style = ship.IsLocked ? CSIsLocked : CSDefaultCenter;

            return row;
        }
            private string GetEquipmentString( ShipData ship )
            {
                StringBuilder sb = new StringBuilder();

                for ( int i = 0; i < ship.Slot.Count; i++ ) {
                    var eq = ship.SlotInstance[i];
                    if ( eq != null )
                        sb.AppendFormat( "[{0}/{1}] {2}\r\n", ship.Aircraft[i], ship.MasterShip.Aircraft[i], eq.NameWithLevel );
                }

                {
                    var exslot = ship.ExpansionSlotInstance;
                    if ( exslot != null )
                        sb.AppendFormat( "補強: {0}\r\n", exslot.NameWithLevel );
                }

                int[] slotmaster = ship.SlotMaster.ToArray();

                sb.AppendFormat( "\r\n昼戦: {0}", Constants.GetDayAttackKind( Calculator.GetDayAttackKind( slotmaster, ship.ShipID, -1 ) ) );
                {
                    int shelling = ship.ShellingPower;
                    int aircraft = ship.AircraftPower;
                    if ( shelling > 0 ) {
                        if ( aircraft > 0 )
                            sb.AppendFormat( " - 砲撃: {0} / 空撃: {1}", shelling, aircraft );
                        else
                            sb.AppendFormat( " - 威力: {0}", shelling );
                    } else if ( aircraft > 0 )
                        sb.AppendFormat( " - 威力: {0}", aircraft );
                }
                sb.AppendLine();

                sb.AppendFormat( "夜戦: {0}", Constants.GetNightAttackKind( Calculator.GetNightAttackKind( slotmaster, ship.ShipID, -1 ) ) );
                {
                    int night = ship.NightBattlePower;
                    if ( night > 0 ) {
                        sb.AppendFormat( " - 威力: {0}", night );
                    }
                }
                sb.AppendLine();

                {
                    int torpedo = ship.TorpedoPower;
                    int asw = ship.AntiSubmarinePower;
                    if ( torpedo > 0 ) {
                        if ( asw > 0 )
                            sb.AppendFormat( "雷撃: {0} / 対潜: {1}\r\n", torpedo, asw );
                        else
                            sb.AppendFormat( "雷撃: {0}\r\n", torpedo );
                    } else if ( asw > 0 )
                        sb.AppendFormat( "対潜: {0}\r\n", asw );
                }

                {
                    int aacutin = Calculator.GetAACutinKind( ship.ShipID, slotmaster );
                    if ( aacutin != 0 ) {
                        sb.AppendFormat( "対空: {0}\r\n", Constants.GetAACutinKind( aacutin ) );
                    }
                }
                {
                    int airsup = Calculator.GetAirSuperiority( ship );
                    int airbattle = ship.AirBattlePower;
                    if ( airsup > 0 ) {
                        if ( airbattle > 0 )
                            sb.AppendFormat( "制空戦力: {0} / 航空威力: {1}\r\n", airsup, airbattle );
                        else
                            sb.AppendFormat( "制空戦力: {0}\r\n", airsup );
                    } else if ( airbattle > 0 )
                        sb.AppendFormat( "航空威力: {0}\r\n", airbattle );
                }

                return sb.ToString();
            }
 // 注: 退避中かどうかまではチェックしない
 private bool IsShipDamaged( ShipData ship, int hp )
 {
     return ship != null &&
         hp > 0 &&
         (double)hp / ship.HPMax <= 0.25 &&
         ship.RepairingDockID == -1 &&
         ship.Level >= LevelBorder &&
         ( ContainsNotLockedShip ? true : ( ship.IsLocked || ship.SlotInstance.Count( q => q != null && q.IsLocked ) > 0 ) ) &&
         ( ContainsSafeShip ? true : !ship.AllSlotInstanceMaster.Select( e => e != null ? e.CategoryType == 23 : false ).Contains( true ) );
 }
 private string GetExEqupimentString(ShipData ship)
 {
     switch (ship.ExpansionSlot)
     {
         case 0:
             return "Locked";
         case -1:
             return GeneralRes.None;
         default:
             return ship.ExpansionSlotInstance.NameWithLevel;
     }
 }
		public static TimeSpan CalculateDockingUnitTime( ShipData ship ) {
			return new TimeSpan( DateTimeHelper.FromAPITimeSpan( ship.RepairTime ).Add( TimeSpan.FromSeconds( -30 ) ).Ticks / ( ship.HPMax - ship.HPCurrent ) );
		}
        /// <summary>
        /// 初期装備を更新します。
        /// </summary>
        /// <param name="ship">対象の艦船。入手直後・改装直後のものに限ります。</param>
        public void UpdateDefaultSlot( ShipData ship )
        {
            int[] slot = new int[ship.Slot.Count];

            for (int i = 0; i < slot.Length; i++) {
                if (ship.Slot[i] == -1)
                {
                    slot[i] = -1;
                }// TODO:出撃から帰還時にNullReferenceExceptionが発生するため、装備のLoadFromResponseには"api_port/port"は無いが、応急措置として装備キーが存在するか調べ追加する。
                else if (!KCDatabase.Instance.Equipments.ContainsKey(ship.Slot[i]))
                {
                    EquipmentData eq = new EquipmentData();
                    eq.LoadFromResponse("api_get_member/ship3", ship.Slot[i]);
                    KCDatabase.Instance.Equipments.Add(eq);
                }
                else
                {
                    slot[i] = KCDatabase.Instance.Equipments[ship.Slot[i]].EquipmentID;
            }
            }

            UpdateDefaultSlot( ship.ShipID, slot );
        }
        private string GetEquipmentString( ShipData ship, int index )
        {
            int current = ship.Aircraft[index];
            int max = ship.MasterShip.Aircraft[index];
            string name = ship.SlotInstance[index] != null ? ship.SlotInstance[index].NameWithLevel : GeneralRes.None;

            if ( index >= ship.MasterShip.SlotSize && ship.Slot[index] == -1 ) {
                return "";

            } else if ( max == 0 ) {
                return name;

            } else if ( current == max ) {
                return string.Format( "[{0}] {1}", current, name );

            } else {
                return string.Format( "[{0}/{1}] {2}", current, max, name );

            }
        }
        /// <summary>
        /// スロット情報を設定します。主に味方艦用です。
        /// </summary>
        /// <param name="ship">当該艦船。</param>
        public void SetSlotList( ShipData ship )
        {
            int slotCount = Math.Max( ship.SlotSize + ( ship.IsExpansionSlotAvailable ? 1 : 0 ), 4 );

            IsExpansionSlotAvailable = ship.IsExpansionSlotAvailable;

            if ( SlotList.Length != slotCount ) {
                SlotList = new SlotItem[slotCount];
                for ( int i = 0; i < SlotList.Length; i++ ) {
                    SlotList[i] = new SlotItem();
                }
            }

            for ( int i = 0; i < Math.Min( slotCount, 5 ); i++ ) {
                var eq = ship.SlotInstance[i];
                SlotList[i].EquipmentID = eq != null ? eq.EquipmentID : -1;
                SlotList[i].AircraftCurrent = ship.Aircraft[i];
                SlotList[i].AircraftMax = ship.MasterShip.Aircraft[i];
                SlotList[i].Level = eq != null ? eq.Level : 0;
                SlotList[i].AircraftLevel = eq != null ? eq.AircraftLevel : 0;
            }

            if ( ship.IsExpansionSlotAvailable ) {
                var eq = ship.ExpansionSlotInstance;
                SlotList[ship.SlotSize].EquipmentID = eq != null ? eq.EquipmentID : -1;
                SlotList[ship.SlotSize].AircraftCurrent =
                SlotList[ship.SlotSize].AircraftMax = 0;
                SlotList[ship.SlotSize].Level = eq != null ? eq.Level : 0;
                SlotList[ship.SlotSize].AircraftLevel = eq != null ? eq.AircraftLevel : 0;
            }

            SlotSize = ship.SlotSize + ( ship.IsExpansionSlotAvailable ? 1 : 0 );

            PropertyChanged();
        }
		/// <summary>
		/// 初期装備を更新します。
		/// </summary>
		/// <param name="ship">対象の艦船。入手直後・改装直後のものに限ります。</param>
		public void UpdateDefaultSlot( ShipData ship ) {

			UpdateDefaultSlot( ship.ShipID, ship.SlotMaster.ToArray() );
		}
        /// <summary>
        /// 制空戦力を求めます。
        /// </summary>
        /// <param name="ship">対象の艦船。</param>
        public static int GetAirSuperiority( ShipData ship )
        {
            if ( ship == null ) return 0;

            if ( Utility.Configuration.Config.FormFleet.AirSuperiorityMethod == 0 ) {
                return GetAirSuperiority( ship.SlotMaster.ToArray(), ship.Aircraft.ToArray() );
            }

            int air = 0;
            var eqs = ship.SlotInstance;
            var aircrafts = ship.Aircraft;

            for ( int i = 0; i < eqs.Count; i++ ) {
                var eq = eqs[i];
                if ( eq != null && aircrafts[i] > 0 ) {

                    int category = eq.MasterEquipment.CategoryType;

                    if ( AircraftLevelBonus.ContainsKey( category ) ) {
                        air += (int)( eq.MasterEquipment.AA * Math.Sqrt( aircrafts[i] ) + Math.Sqrt( AircraftExpTable[eq.AircraftLevel] / 10.0 ) + AircraftLevelBonus[category][eq.AircraftLevel] );
                    }

                }
            }

            return air;
        }
        /// <summary>
        /// 制空戦力を求めます。
        /// </summary>
        /// <param name="ship">対象の艦船。</param>
        public static int GetAirSuperiority( ShipData ship )
        {
            if ( Utility.Configuration.Config.FormFleet.AirSuperiorityMethod == 0 ) {
                return GetAirSuperiority( ship.SlotMaster.ToArray(), ship.Aircraft.ToArray() );
            }

            int air = 0;		//checkme: 場合によっては double にする必要があるかも
            var eqs = ship.SlotInstance;
            var aircrafts = ship.Aircraft;

            for ( int i = 0; i < eqs.Count; i++ ) {
                var eq = eqs[i];
                if ( eq != null && aircrafts[i] > 0 ) {

                    int category = eq.MasterEquipment.CategoryType;

                    if ( AirSuperiorityBonus.ContainsKey( category ) ) {
                        air += (int)( eq.MasterEquipment.AA * Math.Sqrt( aircrafts[i] ) );

                        if ( eq.AircraftLevel == 7 )
                            air += AirSuperiorityBonus[category];
                    }

                }
            }

            return air;
        }
        /// <summary>
        /// スロット情報を設定します。主に味方艦用です。
        /// </summary>
        /// <param name="ship">当該艦船。</param>
        public void SetSlotList( ShipData ship )
        {
            int slotCount = Math.Max( ship.MasterShip.SlotSize, 4 );

            if ( SlotList.Length != slotCount ) {
                SlotList = new SlotItem[slotCount];
                for ( int i = 0; i < SlotList.Length; i++ ) {
                    SlotList[i] = new SlotItem();
                }
            }

            for ( int i = 0; i < SlotList.Length; i++ ) {
                var eq = ship.SlotInstance[i];
                SlotList[i].EquipmentID = eq != null ? eq.EquipmentID : -1;
                SlotList[i].AircraftCurrent = ship.Aircraft[i];
                SlotList[i].AircraftMax = ship.MasterShip.Aircraft[i];
            }

            SlotSize = ship.MasterShip.SlotSize;

            PropertyChanged();
        }
            private string GetEquipmentString( ShipData ship )
            {
                StringBuilder sb = new StringBuilder();

                for ( int i = 0; i < ship.Slot.Count; i++ ) {
                    if ( ship.SlotInstance[i] != null )
                        sb.AppendFormat( "[{0}/{1}] {2}\r\n", ship.Aircraft[i], ship.MasterShip.Aircraft[i], KCDatabase.Instance.Equipments[ship.Slot[i]].NameWithLevel );
                }

                int[] slotmaster = ship.SlotMaster.ToArray();

                sb.AppendFormat( "\r\n昼戦: {0}\r\n夜戦: {1}\r\n",
                    Constants.GetDayAttackKind( Calculator.GetDayAttackKind( slotmaster, ship.ShipID, -1 ) ),
                    Constants.GetNightAttackKind( Calculator.GetNightAttackKind( slotmaster, ship.ShipID, -1 ) ) );
                {
                    int aacutin = Calculator.GetAACutinKind( ship.ShipID, slotmaster );
                    if ( aacutin != 0 ) {
                        sb.AppendFormat( "対空: {0}\r\n", Constants.GetAACutinKind( aacutin ) );
                    }
                }
                {
                    int airsup = Calculator.GetAirSuperiority( ship );
                    if ( airsup > 0 ) {
                        sb.AppendFormat( "制空戦力: {0}\r\n", airsup );
                    }
                }

                return sb.ToString();
            }
 private string GetEquipmentString( ShipData ship, int index )
 {
     if ( index < 5 ) {
         return ( index >= ship.SlotSize && ship.Slot[index] == -1 ) ? "" :
             ship.SlotInstance[index] == null ? "(なし)" : ship.SlotInstance[index].NameWithLevel;
     } else {
         return ship.ExpansionSlot == 0 ? "" :
             ship.ExpansionSlotInstance == null ? "(なし)" : ship.ExpansionSlotInstance.NameWithLevel;
     }
 }
        /// <summary>
        /// ShipView用の新しい行のインスタンスを作成します。
        /// </summary>
        /// <param name="ship">追加する艦娘データ。</param>
        private DataGridViewRow CreateShipViewRow( ShipData ship )
        {
            if ( ship == null ) return null;

            DataGridViewRow row = new DataGridViewRow();
            row.CreateCells( ShipView );

            row.SetValues(
                ship.MasterID,
                ship.MasterShip.ShipType,
                ship.MasterShip.Name,
                ship.Level,
                ship.ExpTotal,
                ship.ExpNext,
                ship.ExpNextRemodel,
                new Fraction( ship.HPCurrent, ship.HPMax ),
                ship.Condition,
                new Fraction( ship.Fuel, ship.MasterShip.Fuel ),
                new Fraction( ship.Ammo, ship.MasterShip.Ammo ),
                GetEquipmentString( ship, 0 ),
                GetEquipmentString( ship, 1 ),
                GetEquipmentString( ship, 2 ),
                GetEquipmentString( ship, 3 ),
                GetEquipmentString( ship, 4 ),
                ship.FleetWithIndex,
                ship.RepairingDockID == -1 ? ship.RepairTime : -1000 + ship.RepairingDockID,
                ship.FirepowerBase,
                ship.FirepowerRemain,
                ship.TorpedoBase,
                ship.TorpedoRemain,
                ship.AABase,
                ship.AARemain,
                ship.ArmorBase,
                ship.ArmorRemain,
                ship.ASWBase,
                ship.EvasionBase,
                ship.LOSBase,
                ship.LuckBase,
                ship.LuckRemain,
                ship.IsLocked,
                ship.SallyArea
                );

            row.Cells[ShipView_Name.Index].Tag = ship.ShipID;
            row.Cells[ShipView_Level.Index].Tag = ship.ExpTotal;

            {
                DataGridViewCellStyle cs;
                double hprate = (double)ship.HPCurrent / Math.Max( ship.HPMax, 1 );
                if ( hprate <= 0.25 )
                    cs = CSRedRight;
                else if ( hprate <= 0.50 )
                    cs = CSOrangeRight;
                else if ( hprate <= 0.75 )
                    cs = CSYellowRight;
                else if ( hprate < 1.00 )
                    cs = CSGreenRight;
                else
                    cs = CSDefaultRight;

                row.Cells[ShipView_HP.Index].Style = cs;
            }
            {
                DataGridViewCellStyle cs;
                if ( ship.Condition < 20 )
                    cs = CSRedRight;
                else if ( ship.Condition < 30 )
                    cs = CSOrangeRight;
                else if ( ship.Condition < Utility.Configuration.Config.Control.ConditionBorder )
                    cs = CSYellowRight;
                else if ( ship.Condition < 50 )
                    cs = CSDefaultRight;
                else
                    cs = CSGreenRight;

                row.Cells[ShipView_Condition.Index].Style = cs;
            }
            row.Cells[ShipView_Fuel.Index].Style = ship.Fuel < ship.MasterShip.Fuel ? CSYellowRight : CSDefaultRight;
            row.Cells[ShipView_Ammo.Index].Style = ship.Fuel < ship.MasterShip.Fuel ? CSYellowRight : CSDefaultRight;
            {
                DataGridViewCellStyle cs;
                if ( ship.RepairTime == 0 )
                    cs = CSDefaultRight;
                else if ( ship.RepairTime < 1000 * 60 * 60 )
                    cs = CSYellowRight;
                else if ( ship.RepairTime < 1000 * 60 * 60 * 6 )
                    cs = CSOrangeRight;
                else
                    cs = CSRedRight;

                row.Cells[ShipView_RepairTime.Index].Style = cs;
            }
            row.Cells[ShipView_FirepowerRemain.Index].Style = ship.FirepowerRemain == 0 ? CSGrayRight : CSDefaultRight;
            row.Cells[ShipView_TorpedoRemain.Index].Style = ship.TorpedoRemain == 0 ? CSGrayRight : CSDefaultRight;
            row.Cells[ShipView_AARemain.Index].Style = ship.AARemain == 0 ? CSGrayRight : CSDefaultRight;
            row.Cells[ShipView_ArmorRemain.Index].Style = ship.ArmorRemain == 0 ? CSGrayRight : CSDefaultRight;
            row.Cells[ShipView_LuckRemain.Index].Style = ship.LuckRemain == 0 ? CSGrayRight : CSDefaultRight;

            row.Cells[ShipView_Locked.Index].Style = ship.IsLocked ? CSIsLocked : CSDefaultCenter;

            return row;
        }