ability = {

	jap_last_stand = {
		name = ABILITY_LAST_STAND
		desc = ABILITY_LAST_STAND_DESC
		
		sound_effect = command_power_ability_offensive
		
		type = army_leader
		
		allowed = {
			is_leading_army_group = no
			is_border_war = no
			OWNER = {
				OR = {
					has_completed_focus = JAP_warrior_spirit
					has_completed_focus = SPA_cultivate_fanaticism
				}
			}
		}
		
		cost = 0.05
		duration = 168
		
		one_time_effect = {
			add_temporary_buff_to_units = {
				combat_defense = 0.2
				combat_entrenchment = 0.25
				org_damage_multiplier = -1.0
				str_damage_multiplier = 0.6
				cannot_retreat_while_defending = 1.0
				
				days = 7
				tooltip = ABILITY_LAST_STAND_TOOLTIP
			}
		}
		
		ai_will_do = { #EAI
			base = -1

			modifier = {
				FROM = {
					EAI_MILITARY_ABILITY_last_stand = yes
				}

				set_temp_variable = { tmp = num_units_defensive_combats }
				divide_temp_variable = { tmp = num_units }
				check_variable = { tmp > 0.1 }

				add = 1000
			}

			modifier = {
				FROM = {
					EAI_MILITARY_ABILITY_last_stand_HOLD = yes
				}

				add = -2000
			}

			modifier = {
				FROM = {
					has_war_support > 0.8
					has_country_flag = EAI_MILITARY_trend_losing_war
				}

				set_temp_variable = { tmp = num_units_defensive_combats }
				divide_temp_variable = { tmp = num_units }
				check_variable = { tmp > 0.5 }
				check_variable = { avg_defensive_combat_status < 0.5 }
				
				add = 2
			}
		}
	}

	jap_even_better_last_stand = {
		name = ABILITY_LAST_STAND
		desc = ABILITY_LAST_STAND_DESC
		
		sound_effect = command_power_ability_offensive
		
		type = army_leader
		
		allowed = {
			is_leading_army_group = no
			is_border_war = no
			OWNER = {
				OR = {
					has_completed_focus = JAP_indoctrination_in_the_military_academy
					has_completed_focus = JAP_issue_the_senjinkun_military_code
				}
			}
		}
		
		cost = 0.05
		duration = 240 
		
		one_time_effect = {
			add_temporary_buff_to_units = {
				combat_defense = 0.2
				combat_entrenchment = 0.25
				org_damage_multiplier = -1.0
				str_damage_multiplier = 0.6
				cannot_retreat_while_defending = 1.0
				
				days = 10
				tooltip = ABILITY_LAST_STAND_TOOLTIP
			}
		}
		
		ai_will_do = {
			factor = -1
			modifier = {
				FROM = {
					has_war_support > 0.4
				}
				
				check_variable = { num_units_defensive_combats > 6 }
				
				set_temp_variable = { temp = avg_defensive_combat_status }
				check_variable = { temp < 0.40 }
				check_variable = { ai_random > temp }
				
				add = 2
			}
		}
	}

	jap_better_staff_office_plan = {
		name = ABILITY_STAFF_OFFICE_PLAN
		desc = ABILITY_STAFF_OFFICE_PLAN_DESC
		
		sound_effect = command_power_ability_defensive
		
		type = army_leader
		
		allowed = {
			is_border_war = no
			OWNER = {
				has_completed_focus = JAP_the_art_of_warfare
			}
		}
		
		cost = 0.06
		duration = 182
		
		unit_modifiers = {
			planning_speed = 4.0
		}
		
		ai_will_do = {
			factor = -1
			modifier = {
				FROM = {
					command_power > 2.0
				}
				check_variable = { num_units > 6 }
				check_variable = { unit_ratio_ready_for_plan > 0.55 }
				check_variable = { avg_unit_planning_ratio < 0.4 }
				
				add = 2
			}
		}
	}

}