#' Conduct a land attack
#'
#' For every land unit attacking, use [roll_dice()] to calculate the number
#' of "hits" on defending units. Each attacking unit makes a successful hit on
#' different roll results (see details). This function is passed to [hits()]
#' and used in `land_battle()`.
#'
#' @details
#' * Infantry: 1 or 2 (see below)
#' * Artillery: 2 or lower
#' * Tanks: 3 or lower
#' * Fighters: 3 or lower
#' * Bombers: 4 or lower
#'
#' For each artillery unit present, one attacking infantry unit makes successful
#' hits on rolls of 2 or lower rather than just 1.
#'
#' @param units A list created by [land_units()].
#' @return A list of logical vectors with hit results for each unit attacking.
#' @examples
#' land_units(i = 6, a = 2, t = 1) %>% attack()
#' @export
attack <- function(units = land_units()) {
r <- list(
infantry = roll_dice(units$i),
artillery = roll_dice(units$a) <= 2,
tanks = roll_dice(units$t) <= 3,
fighters = roll_dice(units$f) <= 3,
bombers = roll_dice(units$b) <= 4
)
r[[1]][r[[1]] == 2][0:min(sum(r[[1]] == 2), units[[2]])] <- 1
r[[1]] <- r[[1]] <= 1
return(r)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.