Skip to content

Commit

Permalink
limit & cause food deaths
Browse files Browse the repository at this point in the history
  • Loading branch information
warronbebster committed Jul 12, 2023
1 parent 51bf34e commit 82fe999
Show file tree
Hide file tree
Showing 19 changed files with 369 additions and 323 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ from(t in MayorGame.City.OngoingAttacks)|> MayorGame.Repo.delete_all([])
from(t in MayorGame.City.Town, update: [set: [logs_deaths_housing: 0]])|> MayorGame.Repo.update_all([])
from(t in MayorGame.City.Town, where: t.treasury < 0, update: [set: [treasury: 0]])|> MayorGame.Repo.update_all([])
reset login dates for dev:
date = Date.utc_today()
from(t in MayorGame.City.Town, update: [set: [last_login: ^date]])|> MayorGame.Repo.update_all([])
from(u in MayorGame.Auth.User, where: u.id == 2115, update: [set: [unconfirmed_email: nil, confirmed_at: ]])|> MayorGame.Repo.update_all([])
from(u in MayorGame.Auth.User, where: u.id == 2115, update: [set: [is_alt: true]])|> MayorGame.Repo.update_all([])
from(u in MayorGame.Auth.User, update: [set: [is_alt: false]])|> MayorGame.Repo.update_all([])
Expand Down
8 changes: 4 additions & 4 deletions bwebs_notes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@


#TODO
# do some optimization to update_city_by_title, see if calculator and migrator can just send changes instead of having the city_live server recalculate it every time
# move logs to a has_many relationship from cities



# move logs to a has_many relationship from cities
# add non-db logs that are just passed through the liveview channel for live logging
# prevent exchange?
# add ability to turn a number of buildings off
# maybe you can choose to open up to migration/trade, you can do everything in your own city (north korea style) but won't get any talented people moving
Expand All @@ -30,6 +28,8 @@
# maybe make pubsub for each city when it's opened to subscribe to updates from other cities attacking u?

# add food
# require cities to have food when a citizen moves there

# add building requirements
# replace "treasury" with "money"

Expand Down
38 changes: 19 additions & 19 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# fly.toml file generated for mayorgame on 2022-11-27T19:12:05-05:00
# fly.toml app configuration file generated for mayorgame on 2023-06-19T16:22:39-07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "mayorgame"
primary_region = "iad"
kill_signal = "SIGTERM"
kill_timeout = 5
processes = []
kill_timeout = "5s"

[experimental]
auto_rollback = true

[deploy]
release_command = "/app/bin/migrate"
Expand All @@ -12,32 +18,26 @@ processes = []
PHX_HOST = "fragile.city"
PORT = "8080"

[experimental]
allowed_public_ports = []
auto_rollback = true

[[services]]
http_checks = []
protocol = "tcp"
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 200
soft_limit = 50
type = "connections"

[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
handlers = ["http"]
force_https = true

[[services.ports]]
handlers = ["tls", "http"]
port = 443
handlers = ["tls", "http"]
[services.concurrency]
type = "connections"
hard_limit = 200
soft_limit = 50

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
grace_period = "1s"
restart_limit = 0
2 changes: 1 addition & 1 deletion lib/mayor_game/city/buildable_statistics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ defmodule MayorGame.City.BuildableStatistics do
workers_by_level: %{integer => integer},
deficient_prereq_next: list(atom),
deficient_prereq_all: list(atom),
resource: %{atom => ResourceStatistics.t()}
resource: %{atom => ResourceStats.t()}
}
end
57 changes: 29 additions & 28 deletions lib/mayor_game/city/resource_statistics.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule MayorGame.City.ResourceStatistics do
defmodule MayorGame.City.ResourceStats do
alias __MODULE__
use Accessible
alias MayorGame.City.{TownStatistics}
alias MayorGame.City.{TownStats}
# education, unlike all other resources, uses a map
# this can complicate things quite a bit. We can make this struct work with maps but it may occur expensive checks for all resources, for the benefit of one resource
# for now, we split it to education_lvl_1, education_lvl_2 etc. And reserve a special education resource for libraries for random drop across all levels
Expand All @@ -18,9 +18,9 @@ defmodule MayorGame.City.ResourceStatistics do
# fn _rng, _number_of_instances -> drop_amount
# fn _rng, _number_of_instances, _city -> drop_amount
@type dropfunction ::
(number, integer -> integer) | (number, integer, TownStatistics.t() -> integer) | nil
(number, integer -> integer) | (number, integer, TownStats.t() -> integer) | nil

@type t :: %ResourceStatistics{
@type t :: %ResourceStats{
title: String.t(),
stock: integer,
storage: integer | nil,
Expand All @@ -29,9 +29,9 @@ defmodule MayorGame.City.ResourceStatistics do
droplist: list({integer, dropfunction})
}

@spec merge(ResourceStatistics.t(), ResourceStatistics.t(), integer) :: ResourceStatistics.t()
@spec merge(ResourceStats.t(), ResourceStats.t(), integer) :: ResourceStats.t()
def merge(source, child, quantity \\ 1) do
%ResourceStatistics{
%ResourceStats{
title: source.title,
stock: source.stock + child.stock * quantity,
storage:
Expand Down Expand Up @@ -64,9 +64,9 @@ defmodule MayorGame.City.ResourceStatistics do
}
end

@spec multiply(ResourceStatistics.t(), integer) :: ResourceStatistics.t()
@spec multiply(ResourceStats.t(), integer) :: ResourceStats.t()
def multiply(source, quantity \\ 1) do
%ResourceStatistics{
%ResourceStats{
title: source.title,
stock: source.stock * quantity,
storage:
Expand All @@ -82,9 +82,9 @@ defmodule MayorGame.City.ResourceStatistics do
end

@spec fromProduces(String.t(), integer, integer | nil, list({integer, dropfunction})) ::
ResourceStatistics.t()
ResourceStats.t()
def fromProduces(title, value, storage \\ nil, droplist \\ []) do
%ResourceStatistics{
%ResourceStats{
title: title,
stock: 0,
storage: storage,
Expand Down Expand Up @@ -112,9 +112,9 @@ defmodule MayorGame.City.ResourceStatistics do
@doc """
I think this creates a new statistic from what's required, which then you can merge with the existing resource statistic
"""
@spec fromRequires(String.t(), integer, integer | nil) :: ResourceStatistics.t()
@spec fromRequires(String.t(), integer, integer | nil) :: ResourceStats.t()
def fromRequires(title, value, storage \\ nil) do
%ResourceStatistics{
%ResourceStats{
title: title,
stock: 0,
storage:
Expand All @@ -139,42 +139,43 @@ defmodule MayorGame.City.ResourceStatistics do
}
end

@spec getStock(ResourceStatistics.t(), integer) :: integer
@spec getStock(ResourceStats.t(), integer) :: integer
def getStock(stat, additive \\ 0) do
stat.stock + additive
end

@spec getStorage(ResourceStatistics.t()) :: integer | nil
@spec getStorage(ResourceStats.t()) :: integer | nil
def getStorage(stat) do
stat.storage
end

@spec getProduction(ResourceStatistics.t()) :: integer
@spec getProduction(ResourceStats.t()) :: integer
def getProduction(stat) do
stat.production
end

@spec getConsumption(ResourceStatistics.t()) :: integer
@spec getConsumption(ResourceStats.t()) :: integer
def getConsumption(stat) do
stat.consumption
end

@spec getNextStock(ResourceStatistics.t()) :: integer
@spec getNextStock(ResourceStats.t()) :: integer
def getNextStock(stat) do
# min(getStock(stat) + getNetProduction(stat), stat.storage)
getStock(stat) + getNetProduction(stat)
end

@spec getNetProduction(ResourceStatistics.t()) :: integer
@spec getNetProduction(ResourceStats.t()) :: integer
def getNetProduction(stat) do
stat.production - stat.consumption
end

@spec expressStock_SI(ResourceStatistics.t(), integer) :: String.t()
@spec expressStock_SI(ResourceStats.t(), integer) :: String.t()
def expressStock_SI(stat, additive \\ 0) do
Number.SI.number_to_si(stat.stock + additive, precision: 3, trim: true)
end

@spec expressStockOverStorage_SI(ResourceStatistics.t(), integer) :: String.t()
@spec expressStockOverStorage_SI(ResourceStats.t(), integer) :: String.t()
def expressStockOverStorage_SI(stat, additive \\ 0) do
if is_nil(stat.storage) do
Number.SI.number_to_si(stat.stock + additive, precision: 3, trim: true)
Expand All @@ -185,34 +186,34 @@ defmodule MayorGame.City.ResourceStatistics do
end
end

@spec expressProduction_SI(ResourceStatistics.t()) :: String.t()
@spec expressProduction_SI(ResourceStats.t()) :: String.t()
def expressProduction_SI(stat) do
Number.SI.number_to_si(stat.production, precision: 3, trim: true)
end

@spec expressConsumption_SI(ResourceStatistics.t()) :: String.t()
@spec expressConsumption_SI(ResourceStats.t()) :: String.t()
def expressConsumption_SI(stat) do
Number.SI.number_to_si(stat.consumption, precision: 3, trim: true)
end

@spec expressNetProduction_SI(ResourceStatistics.t()) :: String.t()
@spec expressNetProduction_SI(ResourceStats.t()) :: String.t()
def expressNetProduction_SI(stat) do
Number.SI.number_to_si(getNetProduction(stat), precision: 3, trim: true)
end

@spec expressAvailableOverSupply_SI(ResourceStatistics.t()) :: String.t()
@spec expressAvailableOverSupply_SI(ResourceStats.t()) :: String.t()
def expressAvailableOverSupply_SI(stat) do
Number.SI.number_to_si(getNetProduction(stat), precision: 3, trim: true) <>
"/" <>
Number.SI.number_to_si(stat.production, precision: 3, trim: true)
end

@spec expressStock_delimited(ResourceStatistics.t(), integer) :: String.t()
@spec expressStock_delimited(ResourceStats.t(), integer) :: String.t()
def expressStock_delimited(stat, additive \\ 0) do
Number.Delimit.number_to_delimited(stat.stock + additive)
end

@spec expressStockOverStorage_delimited(ResourceStatistics.t(), integer) :: String.t()
@spec expressStockOverStorage_delimited(ResourceStats.t(), integer) :: String.t()
def expressStockOverStorage_delimited(stat, additive \\ 0) do
if is_nil(stat.storage) do
Number.Delimit.number_to_delimited(stat.stock + additive)
Expand All @@ -223,12 +224,12 @@ defmodule MayorGame.City.ResourceStatistics do
end
end

@spec expressNetProduction_delimited(ResourceStatistics.t()) :: String.t()
@spec expressNetProduction_delimited(ResourceStats.t()) :: String.t()
def expressNetProduction_delimited(stat) do
Number.Delimit.number_to_delimited(getNetProduction(stat))
end

@spec expressAvailableOverSupply_delimited(ResourceStatistics.t()) :: String.t()
@spec expressAvailableOverSupply_delimited(ResourceStats.t()) :: String.t()
def expressAvailableOverSupply_delimited(stat) do
Number.Delimit.number_to_delimited(getNetProduction(stat)) <>
"/" <> Number.Delimit.number_to_delimited(stat.production)
Expand Down
Loading

0 comments on commit 82fe999

Please sign in to comment.