Skip to content

Commit

Permalink
Merge pull request #4 from Rucknium/main
Browse files Browse the repository at this point in the history
Added Shiny tab to search for best flag placement; Misc improvements to RPC protocol; Embed concordance tables in package
  • Loading branch information
Syksy authored Jul 19, 2021
2 parents 8f56e1b + 77366ca commit 4f71dd9
Show file tree
Hide file tree
Showing 32 changed files with 1,146 additions and 82 deletions.
8 changes: 7 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: TownforgeR
Title: R-package for handling Townforge related data
Version: 0.0.12
Version: 0.0.14
Authors@R: c(person("Teemu Daniel", "Laajala", email = "teelaa@utu.fi",
role = c("aut", "cre")),
person(given = "Rucknium", email = "Rucknium@protonmail.com",
Expand All @@ -21,4 +21,10 @@ Imports:
bslib,
thematic,
readr,
stringr,
plyr,
Matrix,
lattice,
DT,
waiter,
Cairo
10 changes: 9 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Generated by roxygen2: do not edit by hand

export(shinyTF)
export(test.mat.image)
export(tf_expand_search_flag)
export(tf_flag_bounds)
export(tf_get_best_flag_map)
export(tf_get_influence_effects)
export(tf_get_min_flag_size_data)
export(tf_infl_grid)
export(tf_infl_location)
export(tf_influence_effects)
export(tf_min_flag_size)
export(tf_parse_accounts)
export(tf_parse_items)
export(tf_parse_markets)
Expand All @@ -13,6 +18,9 @@ export(tf_parse_nft_png)
export(tf_parse_nfts)
export(tf_plot_influence)
export(tf_rpc_curl)
export(tf_search_best_flags)
export(tf_shiny_item_info)
export(tf_shiny_nft_png)
import(Matrix)
import(grid)
import(lattice)
47 changes: 46 additions & 1 deletion R/extract-game-mechanics.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @details Construct influence effects matrix
#'
#' @export
tf_influence_effects <- function(source.dir = "https://git.townforge.net/townforge/townforge/raw/branch/cc", ...) {
tf_get_influence_effects <- function(source.dir = "https://git.townforge.net/townforge/townforge/raw/branch/cc", ...) {

source.dir <- gsub("/+$", "", source.dir)

Expand Down Expand Up @@ -64,3 +64,48 @@ tf_influence_effects <- function(source.dir = "https://git.townforge.net/townfor
list(bonus = bonus.infl.mat, need = need.infl.mat, penalty = penalty.infl.mat)

}









#' Construct minimum flag size data from Townforge C++ file
#'
#' Description
#'
#' @param source.dir directory of Townforge source
#' @param ... TODO
#'
#' @details Construct minimum flag size data
#'
#' @export
#'
tf_get_min_flag_size_data <- function(source.dir = "https://git.townforge.net/townforge/townforge/raw/branch/cc", ...) {

source.dir <- gsub("/+$", "", source.dir)

cc.v <- readLines(paste0(source.dir, "/src/cc/cc.cpp"))

cc.v <- cc.v[grep("get_min_size_for_building", cc.v)[1]:length(cc.v)]

cc.v <- cc.v[grepl("case ROLE_[A-Z0-9]+: return scale[(]", cc.v)]
cc.v <- cc.v[ ! grepl("ROAD", cc.v)]
# Remove road since it is too complicated
building.role <- stringr::str_extract(cc.v, "ROLE_[A-Z0-9]+")

cc.v <- gsub("(case ROLE_[A-Z0-9]+: return scale[(])(.+)([)];)", "\\2", cc.v)
cc.df <- as.data.frame(apply(do.call(rbind, strsplit(cc.v, ",")), MARGIN = 2, FUN = as.numeric))
colnames(cc.df) <- c("lowest", "highest")
cc.df$building.role <- building.role
min.size.scale.df <- cc.df[, c("building.role", "lowest", "highest")]

min.size.scale.df
}




Loading

0 comments on commit 4f71dd9

Please sign in to comment.