gameconstants

package
v0.0.0-...-ce97658 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2024 License: Apache-2.0 Imports: 2 Imported by: 6

README

gameconstants

This package provides various interesting constants for games such as movement speeds, carrying capacities, and more.

Documentation

Overview

Package gameconstants provides various interesting constants for games.

Index

Constants

View Source
const (
	// Approximate movement speeds for the average person.
	WalkingSpeed = 1.4 // m/s
	RunningSpeed = 5.0 // m/s

	// Approximate view distance for the average person in meters for a
	// normal sized object.
	// NOTE: The earth's curvature limits the view distance to 5km
	ViewDistanceNormal = 1000.0 // m
	ViewDistanceDark   = 100.0  // m

	// Average view cone for the average person in degrees.
	ViewConeCentral     = 60.0  // degrees
	ViewConePeripherial = 180.0 // degrees

	// Approximate sensory distance for the average person in meters.
	DistanceHearing = 100.0 // m
	DistanceSmell   = 10.0  // m
	DistanceTouch   = 0.7   // m
	DistanceTaste   = 0.1   // m

	// Human carrying capacity.
	CarryingCapacity = 100.0 // kg

	// Horse properties.
	HorseTrotSpeed   = 5.0  // m/s
	HorseCanterSpeed = 8.0  // m/s
	HorseGallopSpeed = 12.0 // m/s
	// This is usually up to 20% of the horse's weight.
	// See: https://www.deephollowranch.com/how-much-weight-can-a-horse-carry/
	HorseCarryingCapacity = 120 // kg

	// Cart properties.
	// NOTE: Horse carts are twice as fast as oxen carts.
	CartSpeedEmpty       = 1.8 // m/s
	CartSpeedLaden       = 1.4 // m/s
	CartCarryingCapacity = 200 // kg (per horse)

	// Bird properties
	BirdSpeed            = 10.0 // m/s
	BirdCarryingCapacity = 0.2  // kg

	// Earth properties.
	EarthGravity                     = 9.81        // m/s^2
	EarthRadius                      = 6371.0      // km
	EarthCircumference               = 40075.0     // km
	EarthSurface                     = 510100000.0 // km^2
	EarthMaxElevation                = 8848.0      // m above sea level
	EarthElevationTemperatureFalloff = 0.0065      // °C/m

	// Sphere constants.
	SphereSurface = 4.0 * math.Pi // 4π - surface of a unit sphere
	SphereVolume  = 4.0 / 3.0     // 4/3 - volume of a unit sphere

	// Ship speed.
	// http://penelope.uchicago.edu/Thayer/E/Journals/TAPA/82/Speed_under_Sail_of_Ancient_Ships*.html
	// TODO: Row boat?
	SailShipSpeedOpenSeaMin = 4 * KnotsToMetersPerSec
	SailShipSpeedOpenSeaMax = 6 * KnotsToMetersPerSec
	SailShipSpeedCoastalMin = 3 * KnotsToMetersPerSec
	SailShipSpeedCoastalMax = 4 * KnotsToMetersPerSec
	KnotsToMetersPerSec     = 0.51444444444444444444444444444444 // m/s
)
View Source
const (
	AvgGrowthPerYearMin = 0.09
	AvgGrowthPerYearMax = 0.20
)

See: https://en.wikipedia.org/wiki/Medieval_demography#Demographic_tables_of_Europe%E2%80%99s_population That's just european though... I'd love to see other data, especially from the middle east and asia (different cultures, different climates).

View Source
const (
	// Land measurements.
	HectareToM2 = 10000.0        // hectars to m^2
	AcreToM2    = 4046.86        // acre to m^2
	AreToM2     = 100.0          // are to m^2
	SqInchToM2  = 0.00064516     // square inch to m^2
	SqFootToM2  = 0.09290304     // square foot to m^2
	SqYardToM2  = 0.83612736     // square yard to m^2
	SqMileToM2  = 2589988.110336 // square mile to m^2

	// Distance measurements.
	InchToM       = 0.0254  // inch to m
	FootToM       = 0.3048  // feet to m
	YardToM       = 0.9144  // yard to m
	MileToM       = 1609.0  // miles to m
	NauticalMiToM = 1852.0  // nautical miles to m
	PoleToM       = 5.0292  // pole to m
	RodToM        = 5.0292  // rod to m
	FurlongToM    = 201.168 // furlong to m
	HandToM       = 0.1016  // hand to m
	LinkToM       = 0.2012  // link to m
	ChainToM      = 20.1168 // chain to m
	CableToM      = 185.2   // cable to m
	LeagueToM     = 4828.03 // league to m

	// Weight measurements.
	OunceToKg       = 0.0283495 // ounces to kg
	PoundToKg       = 0.453592  // pounds to kg
	StoneToKg       = 6.35029   // stone to kg
	USTonToKg       = 907.18474 // US ton to kg
	ImperialTonToKg = 1016.05   // imperial ton to kg
)
View Source
const (
	SettlementPopMinHamlet     = 50
	SettlementPopMinVillage    = 200
	SettlementPopMinTownSmall  = 2000
	SettlementPopMinTownMedium = 6000
	SettlementPopMinTownLarge  = 15000
	SettlementPopMinCitySmall  = 30000
	SettlementPopMinCityMedium = 60000
	SettlementPopMinCityLarge  = 125000
	SettlementPopMinMetropolis = 250000
)

Min population for each settlement type. NOTE: These values are pure guesswork. I chose the values so they'd roughly double with each step in the larger settlement types.

View Source
const (
	CampPopMinFamily = 10
	CampPopMinClan   = 50
	CampPopMinTribe  = 200
)

Min population for each nomad camp type. NOTE: These values are pure guesswork.

Variables

This section is empty.

Functions

func CalcPopulationAfterNYears

func CalcPopulationAfterNYears(startVal int, t, growthRate float64) float64

For calculating the population growth, we'd have to take into account if there was a famine, war, etc. in the past years. For now we just assume a constant growth rate. 'startVal' is the starting population. 't' is the time that has passed 'growthRate' is the average growth rate in the time interval used to measure 't'. NOTE: If 't' is in years, then the growth rate should be in growth / year as well.

func ConvertGrowthRate

func ConvertGrowthRate(factor, growthRate float64) float64

ConvertGrowthRate converts a given growth rate to the growth rate of a given factor. For example, to convert yearly growth to daily growth, the factor would be 1/365.

func DiesAtAge

func DiesAtAge(age int) bool

DiesAtAge returns true if the person of the given age dies of natural causes. From: https://github.com/Kontari/Village/blob/master/src/death.py TODO: Mortality under 35 and child mortaity is not yet implemented. TODO: Figure out proper chance of death?

func DiesAtAgeWithinNDays

func DiesAtAgeWithinNDays(age, n int) bool

DiesAtAgeWithinNDays returns true if the person of the given age dies of natural causes within the next n days. TODO: Deduplicate code with DiesAtAge.

func FahrenheitToCelsius

func FahrenheitToCelsius(f float64) float64

FahrenheitToCelsius converts a temperature in Fahrenheit to Celsius.

func KelvinToCelsius

func KelvinToCelsius(k float64) float64

KelvinToCelsius converts a temperature in Kelvin to Celsius.

Types

type NomadCampType

type NomadCampType int

NomadCampType indicates what type of camp a camp is.

const (
	CampTypeUnset NomadCampType = iota
	CampTypeSmall
	CampTypeFamily
	CampTypeClan
	CampTypeTribe
)

Camp types.

func GetNomadCampType

func GetNomadCampType(pop int) NomadCampType

GetNomadCampType returns the camp type for a given population.

func (NomadCampType) String

func (c NomadCampType) String() string

String returns a human readable string for the camp type.

type SettlementType

type SettlementType int

SettlementType indicates what type of settlement a settlement is. (Thorpe, Hamlet, Village, Town, City, Metropolis)

const (
	SettlementTypeUnset SettlementType = iota
	SettlementTypeThorpe
	SettlementTypeHamlet
	SettlementTypeVillage
	SettlementTypeTownSmall
	SettlementTypeTownMedium
	SettlementTypeTownLarge
	SettlementTypeCitySmall
	SettlementTypeCityMedium
	SettlementTypeCityLarge
	SettlementTypeMetropolis
)

Settlement types (per population).

func GetSettlementType

func GetSettlementType(pop int) SettlementType

GetSettlementType returns the settlement type for a given population.

func (SettlementType) String

func (s SettlementType) String() string

String returns a human readable string for the settlement type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL