R/defend.R

Defines functions defend

Documented in defend

#' Conduct a land defense
#'
#' For every land unit defending, use [roll_dice()] to calculate the number
#' of "hits" on attacking units. Each defending unit makes a successful hit on
#' different roll results (see details). This function is passed to [hits()]
#' and used in `land_battle()`.
#'
#' @details
#' * Infantry: 2 or lower
#' * Artillery: 2 or lower
#' * Tanks: 3 or lower
#' * Fighters: 3 or lower
#' * Bombers: 1
#'
#' @param units A list created by [land_units()].
#' @return A list of logical vectors with hit results for each unit defending.
#' @examples
#' land_units(i = 10, f = 1) %>% defend()
#' @export
defend <- function(units = land_units()) {
  list(
    inf  = roll_dice(units$i) <= 2,
    art  = roll_dice(units$a) <= 2,
    tank = roll_dice(units$t) <= 3,
    fig  = roll_dice(units$f) <= 4,
    bomb = roll_dice(units$b) <= 1
  )
}
kiernann/aaa documentation built on Feb. 10, 2020, 1:23 a.m.