Documentation ¶
Index ¶
- Constants
- func CheckSkillDependencies(owned SetOfSkillTypes, required, forbidden []string) bool
- type ActionArgAssault
- type ActionArgMove
- type Army
- func (a *Army) ApplyAgressivity(w *Region)
- func (a *Army) BreakBuilding(w *Region, pCity *City)
- func (a *Army) Cancel(w *Region) error
- func (a *Army) Conquer(w *World, pCity *City)
- func (a *Army) DeferAttack(w *Region, loc uint64, args ActionArgAssault) error
- func (a *Army) DeferDefend(w *Region, loc uint64) error
- func (a *Army) DeferDisband(w *Region, loc uint64) error
- func (a *Army) DeferMove(w *Region, loc uint64, args ActionArgMove) error
- func (a *Army) DeferWait(w *Region, loc uint64) error
- func (a *Army) Deposit(w *Region, pCity *City)
- func (a *Army) Disband(w *Region, pCity *City, shouldNotify bool)
- func (a *Army) Flea(w *Region) error
- func (a *Army) Flip(w *Region) error
- func (a *Army) JoinCityAttack(w *Region, pCity *City)
- func (a *Army) JoinCityDefence(w *Region, pCity *City) bool
- func (a *Army) Massacre(w *Region, pCity *City)
- func (a *Army) Move(ctx context.Context, r *Region)
- func (a *Army) PopCommand()
- type Artifact
- type Building
- type BuildingType
- type City
- func (c *City) ApplyModel(model *City)
- func (c *City) ApplyNamedModel(r *Region, modelName string) error
- func (c *City) Build(w *Region, bID string) (string, error)
- func (c *City) BuildingFrontier(w *Region) []*BuildingType
- func (c *City) ComputePopularity(r *Region) int64
- func (c *City) ComputeProduction(r *Region) *CityProduction
- func (c *City) ComputeStats(r *Region) CityStats
- func (c *City) ComputeStock(r *Region) *CityStock
- func (c *City) ConquerCity(w *World, other *City)
- func (c *City) CreateArmyDefence(w *Region) (*Army, error)
- func (c *City) CreateArmyFromIds(w *Region, ids ...string) (*Army, error)
- func (c *City) CreateArmyFromUnit(w *Region, units ...*Unit) (*Army, error)
- func (c *City) CreateEmptyArmy(_ *Region) *Army
- func (c *City) CreateTransport(w *Region, r Resources) (*Army, error)
- func (c *City) GainFreedom(w *World)
- func (c *City) GetBuilding(id string) *Building
- func (c *City) GetLieges() []*City
- func (c *City) GetSkill(id string) *Skill
- func (c *City) GetUnit(id string) *Unit
- func (c *City) InstantBuild(w *Region, bID string) error
- func (c *City) InstantStudy(w *Region, typeID string) error
- func (c *City) InstantTrain(w *Region, typeID string) error
- func (c *City) LiberateCity(w *World, other *City)
- func (c *City) Produce(_ context.Context, w *Region)
- func (c *City) ProduceLocally(w *Region, p *CityProduction) Resources
- func (c *City) SendResourcesTo(w *Region, overlord *City, amount Resources) error
- func (c *City) SetTaxRate(m ResourcesMultiplier)
- func (c *City) SetUniformTaxRate(nb float64)
- func (c *City) SkillFrontier(w *Region) []*SkillType
- func (c *City) StartBuilding(t *BuildingType) *Building
- func (c *City) StartStudy(pType *SkillType) *Skill
- func (c *City) StartUnit(w *Region, pType *UnitType) *Unit
- func (c *City) Study(w *Region, typeID string) (string, error)
- func (c *City) Train(w *Region, typeID string) (string, error)
- func (c *City) TransferOwnResources(a *Army, r Resources) error
- func (c *City) TransferOwnUnit(a *Army, units ...string) error
- func (c *City) UnitAllowed(t *UnitType) bool
- func (c *City) UnitFrontier(w *Region) []*UnitType
- type CityActivityCounters
- type CityProduction
- type CityStats
- type CityStock
- type Command
- type Configuration
- type DefinitionsBase
- type EventArmy
- type EventSkill
- type EventUnits
- type Fight
- type MapClient
- type NamedCity
- type Notifier
- type Region
- func (reg *Region) Check() error
- func (reg *Region) CityCreate(loc uint64) (*City, error)
- func (reg *Region) CityGet(id uint64) *City
- func (reg *Region) GetCitiesByOwner(idChar string) []*City
- func (reg *Region) GetWorld() *World
- func (reg *Region) Move(ctx context.Context)
- func (reg *Region) PostLoad() error
- func (reg *Region) Produce(ctx context.Context)
- func (reg *Region) UnitGet(city uint64, id string) *Unit
- type ResourceModifiers
- type Resources
- func (r *Resources) Add(o Resources)
- func (r *Resources) Apply(rm ...ResourceModifiers)
- func (r Resources) Copy() Resources
- func (r Resources) Equals(o Resources) bool
- func (r Resources) GreaterOrEqualTo(o Resources) bool
- func (r *Resources) Increment(ri ResourcesIncrement)
- func (r Resources) IsZero() bool
- func (r *Resources) Multiply(rm ResourcesMultiplier)
- func (r *Resources) Remove(o Resources)
- func (r *Resources) Set(o Resources)
- func (r *Resources) SetValue(v uint64)
- func (r *Resources) TrimTo(limit Resources)
- func (r *Resources) Zero()
- type ResourcesIncrement
- type ResourcesMultiplier
- type SetOfArmies
- func (s *SetOfArmies) Add(a *Army)
- func (s SetOfArmies) Check() error
- func (s SetOfArmies) CheckThenFail()
- func (s SetOfArmies) Get(id string) *Army
- func (s SetOfArmies) Has(id string) bool
- func (s SetOfArmies) Len() int
- func (s SetOfArmies) Less(i, j int) bool
- func (s *SetOfArmies) Remove(a *Army)
- func (s *SetOfArmies) RemovePK(pk string)
- func (s SetOfArmies) Slice(marker string, max uint32) []*Army
- func (s SetOfArmies) Swap(i, j int)
- type SetOfArtifacts
- func (s *SetOfArtifacts) Add(a *Artifact)
- func (s SetOfArtifacts) Check() error
- func (s SetOfArtifacts) CheckThenFail()
- func (s SetOfArtifacts) Get(id string) *Artifact
- func (s SetOfArtifacts) Has(id string) bool
- func (s SetOfArtifacts) Len() int
- func (s SetOfArtifacts) Less(i, j int) bool
- func (s *SetOfArtifacts) Remove(a *Artifact)
- func (s *SetOfArtifacts) RemovePK(pk string)
- func (s SetOfArtifacts) Slice(marker string, max uint32) []*Artifact
- func (s SetOfArtifacts) Swap(i, j int)
- type SetOfBuildingTypes
- func (s *SetOfBuildingTypes) Add(a *BuildingType)
- func (s SetOfBuildingTypes) Check() error
- func (s SetOfBuildingTypes) CheckThenFail()
- func (s SetOfBuildingTypes) Frontier(pop int64, built []*Building, owned []*Skill) []*BuildingType
- func (s SetOfBuildingTypes) Get(id string) *BuildingType
- func (s SetOfBuildingTypes) Has(id string) bool
- func (s SetOfBuildingTypes) Len() int
- func (s SetOfBuildingTypes) Less(i, j int) bool
- func (s *SetOfBuildingTypes) Remove(a *BuildingType)
- func (s *SetOfBuildingTypes) RemovePK(pk string)
- func (s SetOfBuildingTypes) Slice(marker string, max uint32) []*BuildingType
- func (s SetOfBuildingTypes) Swap(i, j int)
- type SetOfBuildings
- func (s *SetOfBuildings) Add(a *Building)
- func (s SetOfBuildings) Check() error
- func (s SetOfBuildings) CheckThenFail()
- func (s SetOfBuildings) Get(id string) *Building
- func (s SetOfBuildings) Has(id string) bool
- func (s SetOfBuildings) Len() int
- func (s SetOfBuildings) Less(i, j int) bool
- func (s *SetOfBuildings) Remove(a *Building)
- func (s *SetOfBuildings) RemovePK(pk string)
- func (s SetOfBuildings) Slice(marker string, max uint32) []*Building
- func (s SetOfBuildings) Swap(i, j int)
- type SetOfCities
- func (s *SetOfCities) Add(a *City)
- func (s SetOfCities) Check() error
- func (s SetOfCities) CheckThenFail()
- func (s SetOfCities) Get(id uint64) *City
- func (s SetOfCities) Has(id uint64) bool
- func (s SetOfCities) Len() int
- func (s SetOfCities) Less(i, j int) bool
- func (s *SetOfCities) Remove(a *City)
- func (s *SetOfCities) RemovePK(pk uint64)
- func (s SetOfCities) Slice(marker uint64, max uint32) []*City
- func (s SetOfCities) Swap(i, j int)
- type SetOfFights
- type SetOfId
- func (s *SetOfId) Add(a uint64)
- func (s SetOfId) Check() error
- func (s SetOfId) CheckThenFail()
- func (s SetOfId) Get(id uint64) uint64
- func (s SetOfId) Has(id uint64) bool
- func (s SetOfId) Len() int
- func (s SetOfId) Less(i, j int) bool
- func (s *SetOfId) Remove(a uint64)
- func (s *SetOfId) RemovePK(pk uint64)
- func (s SetOfId) Slice(marker uint64, max uint32) []uint64
- func (s SetOfId) Swap(i, j int)
- type SetOfRegions
- func (s *SetOfRegions) Add(a *Region)
- func (s SetOfRegions) Check() error
- func (s SetOfRegions) CheckThenFail()
- func (s SetOfRegions) Get(id string) *Region
- func (s SetOfRegions) Has(id string) bool
- func (s SetOfRegions) Len() int
- func (s SetOfRegions) Less(i, j int) bool
- func (s *SetOfRegions) Remove(a *Region)
- func (s *SetOfRegions) RemovePK(pk string)
- func (s SetOfRegions) Slice(marker string, max uint32) []*Region
- func (s SetOfRegions) Swap(i, j int)
- type SetOfSkillTypes
- func (s *SetOfSkillTypes) Add(a *SkillType)
- func (s SetOfSkillTypes) Check() error
- func (s SetOfSkillTypes) CheckThenFail()
- func (s SetOfSkillTypes) Frontier(owned []*Skill) []*SkillType
- func (s SetOfSkillTypes) Get(id string) *SkillType
- func (s SetOfSkillTypes) Has(id string) bool
- func (s SetOfSkillTypes) Len() int
- func (s SetOfSkillTypes) Less(i, j int) bool
- func (s *SetOfSkillTypes) Remove(a *SkillType)
- func (s *SetOfSkillTypes) RemovePK(pk string)
- func (s SetOfSkillTypes) Slice(marker string, max uint32) []*SkillType
- func (s SetOfSkillTypes) Swap(i, j int)
- type SetOfSkills
- func (s *SetOfSkills) Add(a *Skill)
- func (s SetOfSkills) Check() error
- func (s SetOfSkills) CheckThenFail()
- func (s SetOfSkills) Get(id string) *Skill
- func (s SetOfSkills) Has(id string) bool
- func (s SetOfSkills) Len() int
- func (s SetOfSkills) Less(i, j int) bool
- func (s *SetOfSkills) Remove(a *Skill)
- func (s *SetOfSkills) RemovePK(pk string)
- func (s SetOfSkills) Slice(marker string, max uint32) []*Skill
- func (s SetOfSkills) Swap(i, j int)
- type SetOfTemplates
- func (s *SetOfTemplates) Add(a *City)
- func (s SetOfTemplates) Check() error
- func (s SetOfTemplates) CheckThenFail()
- func (s SetOfTemplates) Get(id string) *City
- func (s SetOfTemplates) Has(id string) bool
- func (s SetOfTemplates) Len() int
- func (s SetOfTemplates) Less(i, j int) bool
- func (s *SetOfTemplates) Remove(a *City)
- func (s *SetOfTemplates) RemovePK(pk string)
- func (s SetOfTemplates) Slice(marker string, max uint32) []*City
- func (s SetOfTemplates) Swap(i, j int)
- type SetOfUnitTypes
- func (s *SetOfUnitTypes) Add(a *UnitType)
- func (s SetOfUnitTypes) Check() error
- func (s SetOfUnitTypes) CheckThenFail()
- func (s SetOfUnitTypes) Frontier(owned []*Building) []*UnitType
- func (s SetOfUnitTypes) Get(id string) *UnitType
- func (s SetOfUnitTypes) Has(id string) bool
- func (s SetOfUnitTypes) Len() int
- func (s SetOfUnitTypes) Less(i, j int) bool
- func (s *SetOfUnitTypes) Remove(a *UnitType)
- func (s *SetOfUnitTypes) RemovePK(pk string)
- func (s SetOfUnitTypes) Slice(marker string, max uint32) []*UnitType
- func (s SetOfUnitTypes) Swap(i, j int)
- type SetOfUnits
- func (s *SetOfUnits) Add(a *Unit)
- func (s SetOfUnits) Check() error
- func (s SetOfUnits) CheckThenFail()
- func (s SetOfUnits) Get(id string) *Unit
- func (s SetOfUnits) Has(id string) bool
- func (s SetOfUnits) Len() int
- func (s SetOfUnits) Less(i, j int) bool
- func (s *SetOfUnits) Remove(a *Unit)
- func (s *SetOfUnits) RemovePK(pk string)
- func (s SetOfUnits) Slice(marker string, max uint32) []*Unit
- func (s SetOfUnits) Swap(i, j int)
- type Skill
- type SkillType
- type Unit
- type UnitType
- type World
- func (w *World) BuildingGetFrontier(pop int64, built []*Building, owned []*Skill) []*BuildingType
- func (w *World) BuildingTypeGet(id string) *BuildingType
- func (w *World) Check() error
- func (w *World) CreateRegion(name, mapName string, cities []NamedCity) (*Region, error)
- func (w *World) LoadDefinitions(basedir string) (err error)
- func (w *World) LoadRegions(basedir string) error
- func (w *World) PostLoad() error
- func (w *World) RLock()
- func (w *World) RUnlock()
- func (w *World) SetMapClient(c MapClient)
- func (w *World) SetNotifier(n Notifier)
- func (w *World) SkillGetFrontier(owned []*Skill) []*SkillType
- func (w *World) SkillTypeGet(id string) *SkillType
- func (w *World) UnitGetFrontier(owned []*Building) []*UnitType
- func (w *World) UnitTypeGet(id string) *UnitType
- func (w *World) WLock()
- func (w *World) WUnlock()
Constants ¶
const ( ResourceActions = iota ResourceGold = iota ResourceCereal = iota ResourceLivestock = iota ResourceStone = iota ResourceWood = iota ResourceMax = iota )
const ( // Disband the Army and transfer its whole content to the local City // If there is no local City at the current position, the content of // the Army is lost. // Argument: ignored CmdCityDisband = "disband" // Like CmdMove but the command doesn't expire // Argument: ignored CmdWait = "wait" // Do nothing. Useful for waypoints // Argument: ActionArgMove CmdMove = "move" // Start a fight or join a running fight on the side of the attackers // Argument: ActionArgAssault CmdCityAttack = "attack" // Join a running fight on the side of the defenders, or Watch the City if // Argument: ignored CmdCityDefend = "defend" )
const ( CityStatePrivIdle = iota CityStatePrivAssigned CityStatePrivConfigured CityStatePrivReady CityStatePrivHeadless CityStatePrivSuspended CityStatePrivAuto CityStatePrivActive CityStatePubIdle CityStatePubAssigned CityStatePubHeadless CityStatePubSuspended CityStatePubAuto CityStatePubActive )
Variables ¶
This section is empty.
Functions ¶
func CheckSkillDependencies ¶
func CheckSkillDependencies(owned SetOfSkillTypes, required, forbidden []string) bool
Types ¶
type ActionArgAssault ¶
type ActionArgAssault struct { // Become the overlord of the City. Overlord bool `json:"overlord,omitempty"` // Break a random building Break bool `json:"break,omitempty"` // Impact the production of the subbsequent seasons Massacre bool `json:"massacre,omitempty"` }
ActionArgAssault tells what to do if the army is victorious
type ActionArgMove ¶
type ActionArgMove struct { // Resources to be transferred Amount Resources `json:"amount,omitempty"` // Artifact to be transferred Artifact uint64 `json:"artifact,omitempty"` // Troops to be transferred Units []uint64 `json:"units,omitempty"` }
ActionArgMove gives additional actions to be performed when the Army reaches its destination.
type Army ¶
type Army struct { // The unique ID of the current Army ID string `json:"Id"` // A display name for the current City Name string // The City that controls the current Army City *City `json:"-"` // The ID of the Fight this Army is involved in. FightID string `json:"fight,omitempty"` // The ID of the Cell the Army is on Cell uint64 `json:",omitempty"` // How many resources are carried by that Army // The set may be empty. Stock Resources `json:",omitempty"` // Units that compose the current Army. // The set may be empty. Units SetOfUnits `json:",omitempty"` // Artifacts carried by the current Army // The set may be empty Artifacts SetOfArtifacts `json:",omitempty"` // The IS of a Cell of the Map that is a goal of the current movement of the Army Targets []Command `json:",omitempty"` // An array of Postures against armies of other cities. // A positive value means "defend" // A negative value means "assault" Postures []int64 `json:",omitempty"` }
Army is the entity able to act on a map. The actions are produced in a queued (fielf :Targets:) and the queue is consumed by a periodical task.
func (*Army) ApplyAgressivity ¶
func (*Army) BreakBuilding ¶
func (*Army) DeferAttack ¶
func (a *Army) DeferAttack(w *Region, loc uint64, args ActionArgAssault) error
func (*Army) Flip ¶
Change the side in the Fight. If the Army was defending, it becomes an attacker, if it was an attacker it becomes a defender.
func (*Army) JoinCityAttack ¶
func (*Army) PopCommand ¶
func (a *Army) PopCommand()
type Building ¶
type BuildingType ¶
type BuildingType struct { // Unique ID of the BuildingType ID string `json:"Id"` // Display name of the current BuildingType Name string // How many ticks for the construction Ticks uint32 `json:",omitempty"` // How much does the production cost to start the the building process. Cost0 Resources // How much does the production cost at each tick. Cost Resources // Has the building to be unique a the City MultipleAllowed bool `json:",omitempty"` // Amount of total popularity required to start the construction of the building PopRequired int64 // Transient bonus of Popularity, when the Building is alive PopBonus int64 // Permanent bonus of Popularity given when the Building is achieved PopBonusBuild int64 // Permanent bonus of Popularity given to the owner of the Building when it is destroyed. PopBonusFall int64 // Permanent bonus of Popularity given to the destroyer of the Building PopBonusDestroy int64 // Permanent bonus of Popularity given to the owner of the Building when it is dismantled. PopBonusDismantle int64 // Impat of the current Building on the total storage capacity of the City. Stock ResourceModifiers // Increment of resources produced by this building. Prod ResourceModifiers // A set of SkillType ID that must all be present in a City to let that City start // this kind of building. Requires []string // A set of SkillType ID that must all be absent in a City to let that City start // this kind of building. Conflicts []string }
type City ¶
type City struct { // The unique ID of the current City/ // It is identical to the ID of the location (Vertex) on the Map. ID uint64 `json:"Id"` // The current FSM state, whose value is valid if chosen among the macros in CityState* State uint32 `json:"state"` // The unique ID of the User in charge of the City. Owner string // The unique ID of a City who is the boss of the current City. // Used for resources production computations. Overlord uint64 // Ratio of the produced resources automatically sent to the Overlord City. TaxRate ResourcesMultiplier Assault *Fight `json:",omitempty"` // The display name of the current City Name string // From Lawful (<0) to Chaotic (>0) (0 for neutral) Chaotic int32 // From Bad (<0) to Good (>0) (0 for neutral) Alignment int32 // Race, Tribe, whatever (0 for unset) EthnicGroup uint32 // Major political orientation (0 for none) PoliticalGroup uint32 // God, Pantheon, Philosophy (0 for unset) Cult uint32 // Permanent Popularity of the current City // The total value is the permanent value plus several "transient" bonus PermanentPopularity int64 // Permanent Health of the current City. In other words, how it resists // to diseases, propagates pandemies, etc. // Higher is better. // The total value is the permanent value plus several "transient" bonus PermanentHealth int64 // Permanent Intelligence of the current City. In other words, how to is // able to spy other and resist to their intelligence assaults. // Higher is better. // The total value is the permanent value plus several "transient" bonus PermanentIntelligence int64 // Number of massacres the current City undergo. // It takes one production turn to recover one Massacre. TicksMassacres uint32 `json:",omitempty"` // Resources stock owned by the current City Stock Resources // Maximum amounts of each resources that might be stored in the town hall // of the city. That limit doesn't consider the modifiers. StockCapacity Resources // Resources produced each round by the City, before the enforcing of // Production Boosts ans Production Multipliers Production Resources Skills SetOfSkills Buildings SetOfBuildings // Units directly defending the current City Units SetOfUnits // Armies under the responsibility of the current City Armies SetOfArmies // Artifacts currently placed in the City. Artifacts SetOfArtifacts // Stats has a self-explanatory name Counters CityActivityCounters // contains filtered or unexported fields }
City is the central point of a game instance. It is also the locking granularity for most actions.
func (*City) ApplyModel ¶
func (*City) Build ¶
Build forwards the call to StartBuilding if all the conditions are met, after the initial fee given in the BuildingType
func (*City) BuildingFrontier ¶
func (c *City) BuildingFrontier(w *Region) []*BuildingType
func (*City) ComputePopularity ¶
ComputePopularity returns the total Popularity of the current City (permanent + transient)
func (*City) ComputeProduction ¶
func (c *City) ComputeProduction(r *Region) *CityProduction
ComputeProduction computes the actual production of the local City, and a summary of the main steps leading to the result. In other words, a summary of all the City assets that have an impact.
func (*City) ComputeStats ¶
ComputeStats computes the gauges and extract the counters to build a CityStats about the current City.
func (*City) ComputeStock ¶
ComputeStock computes the actual stock of the local City, and a summary of the main steps leading to the result. In other words, a summary of all the City assets that have an impact.
func (*City) ConquerCity ¶
func (*City) CreateArmyDefence ¶
Create an Army made of all the Units defending the City
func (*City) CreateArmyFromIds ¶
Create an Army made of some Unit of the City
func (*City) CreateArmyFromUnit ¶
Create an Army made of some Unit of the City
func (*City) CreateTransport ¶
Create an Army carrying resources you own
func (*City) GainFreedom ¶
func (*City) GetBuilding ¶
GetBuilding returns a Building owned by the current City, given the Building ID
func (*City) InstantBuild ¶
Build forwards the call to StartBuilding if all the conditions are met, after the initial fee given in the BuildingType
func (*City) LiberateCity ¶
func (*City) ProduceLocally ¶
func (c *City) ProduceLocally(w *Region, p *CityProduction) Resources
Play one round of local production and return the
func (*City) SendResourcesTo ¶
func (*City) SetTaxRate ¶
func (c *City) SetTaxRate(m ResourcesMultiplier)
Set the given tax rate to the current City.
func (*City) SetUniformTaxRate ¶
Set a tax rate on the current City, with the same ratio on every Resource.
func (*City) SkillFrontier ¶
func (*City) StartBuilding ¶
func (c *City) StartBuilding(t *BuildingType) *Building
StartBuilding declares a new Building with the given type and the ticks gauge at its max No check is performed to verify the City has all the requirements.
func (*City) StartStudy ¶
StartStudy declares a new Skill with the given type and the tick sgauge at its max
func (*City) StartUnit ¶
Create a Unit of the given UnitType. No check is performed to verify the City has all the requirements.
func (*City) Train ¶
Start the training of a Unit of the given UnitType (id). The whole chain of requirements will be checked.
func (*City) UnitAllowed ¶
check the current City has all the requirements to train a Unti of the given UnitType.
func (*City) UnitFrontier ¶
Return a collection of UnitType that may be trained by the current City because all the requirements are met. Each UnitType 'p' returned validates 'c.UnitAllowed(p)'.
type CityActivityCounters ¶
type CityActivityCounters struct { ResourceProduced Resources ResourceSent Resources ResourceReceived Resources TaxSent Resources TaxReceived Resources Moves uint64 FightsJoined uint64 FightsLeft uint64 FightsWon uint64 FightsLost uint64 UnitsRaised uint64 UnitsLost uint64 }
CityActivityCounters gathers counters that depict the activity of the City and that are continuously updated by the regions service.
func (*CityActivityCounters) Reset ¶
func (cnt *CityActivityCounters) Reset()
type CityProduction ¶
type CityProduction struct { Base Resources Skill ResourceModifiers Buildings ResourceModifiers Actual Resources }
type CityStats ¶
type CityStats struct { // Gauges StockCapacity Resources StockUsage Resources // A measure of the City's evolution, only the building aspects ScoreBuildings uint64 // A measure of the City's evolution, only the skills aspects ScoreSkill uint64 // A measure of the City's evolution, only the military aspects ScoreMilitary uint64 Popularity int64 // Counters Activity CityActivityCounters }
CityStats gathers gauges and counters that give a hint on the activity of a City. The counters, that are centralized in the Activity field, are extracted as-is from a struct that is continuously updated while the gauges are mostly computed.
type CityStock ¶
type CityStock struct { Base Resources Skill ResourceModifiers Buildings ResourceModifiers Actual Resources Usage Resources }
type Command ¶
type Command struct { // The unique ID of the Cell to target Cell uint64 // What to do once arrived at the given Cell. Action string `json:"action"` // Json Args string `json:"args"` }
Command is a queued order for a specific Army.
type Configuration ¶
type Configuration struct { // Ratio applied to the production of resources that is applied for each // Massacre underwent by any city. It only impacts the production of the City itself. MassacreImpact float64 // Should resource transfers happen instantly or should an actual transport // be emitted by the sender? Set to `true` for an instant transfer or to // `false` for a transport. InstantTransfers bool // Permanent bonus to the Popularity when a City creates an Army PopBonusArmyCreate int64 // Permanent bonus to the Popularity when a City disband an Army PopBonusArmyDisband int64 // Transient bonus to the Popularity of a City for each of its live Army PopBonusArmyAlive int64 // Default Overlord rate: percentage of the production of a City that is // taxed by its Overlord RateOverlord float64 // A city pattern is picked randomly among this set when a city is created. // So the configuration of the world may introduce a variation between // Cities CityPatterns []City }
type DefinitionsBase ¶
type DefinitionsBase struct { // All the possible Units that can be trained or hired in a World // IMMUTABLE: Only read accesses allowed. Units SetOfUnitTypes // All the possible Buildings that can be spanwed in Cities of the current World // IMMUTABLE: Only read accesses allowed. Buildings SetOfBuildingTypes // All the possible Skill that can be learned in Cities of the current World // IMMUTABLE: Only read accesses allowed. Skills SetOfSkillTypes }
func (*DefinitionsBase) Check ¶
func (defs *DefinitionsBase) Check() error
type EventSkill ¶
type EventSkill interface { // Item collects the City 'who' which progresses in the learning of the Skill 'k' Item(who *City, k *SkillType) EventSkill // Step collects about the progression in the earning of the Skill referenced by Item Step(current, max uint64) EventSkill // Send emits the event to the collector. Send() }
EventSkill defines the builder of an event that informs about the progression of a skill
type EventUnits ¶
type EventUnits interface { Item(who *City, u *UnitType) EventUnits Step(current, max uint64) EventUnits Send() }
type Fight ¶
type Fight struct { // The unique ID of the ID string `json:"Id"` // The unique ID of the MapVertex the current Fight is happening on. Cell uint64 // The set of ID of armies involved in the current Fight on the "attack" side // (the side that initiated the fight) Attack SetOfArmies /// The set of ID of armies involved in the current Fight on the "defence" side // (the side that has been force-pulled). Defense SetOfArmies }
type MapClient ¶
type MapClient interface { // Step resolves the next step of the from src to dst // the context is typically inheritated from the original request context. Step(ctx context.Context, mapName string, src, dst uint64) (uint64, error) }
Map actions that are exposed to a World
type NamedCity ¶
NamedCity is the information that a City with named Name should exist at the position ID on the graph map.
type Notifier ¶
type Notifier interface { // Prepare a notification context to inform :to: of the movement of the army :a:. Army(log *City) EventArmy // Prepare a notification context to inform :to: of the evolution of the skill of someone. Skill(log *City) EventSkill // Prepare a notification context to inform :to: of someone hiring troops Units(log *City) EventUnits }
type Region ¶
type Region struct { // Unique name of the region Name string // Identifier of the map in use for the current Region MapName string // All the cities present on the Region Cities SetOfCities // Fights currently happening. The armies involved in the Fight are owned // By the Fight and do not appear in the "Armies" field. Fights SetOfFights Models SetOfTemplates // contains filtered or unexported fields }
func (*Region) GetCitiesByOwner ¶
func (*Region) Move ¶
Move performs a movement round that involves all the armies of all the cities on the map of the region. The round action might take long. But there is no notion of a transaction. As a consequence, the action will ignore the cancellation signal brought by the context.Context.
type ResourceModifiers ¶
type ResourceModifiers struct { Mult ResourcesMultiplier Plus ResourcesIncrement }
func ResourceModifierNoop ¶
func ResourceModifierNoop() ResourceModifiers
func ResourceModifierUniform ¶
func ResourceModifierUniform(mult float64, inc int64) ResourceModifiers
func (*ResourceModifiers) ComposeWith ¶
func (o0 *ResourceModifiers) ComposeWith(o1 ResourceModifiers)
func (ResourceModifiers) Equals ¶
func (o0 ResourceModifiers) Equals(o1 ResourceModifiers) bool
type Resources ¶
type Resources [ResourceMax]uint64
func ResourcesUniform ¶
func (*Resources) Apply ¶
func (r *Resources) Apply(rm ...ResourceModifiers)
func (Resources) GreaterOrEqualTo ¶
func (*Resources) Increment ¶
func (r *Resources) Increment(ri ResourcesIncrement)
func (*Resources) Multiply ¶
func (r *Resources) Multiply(rm ResourcesMultiplier)
type ResourcesIncrement ¶
type ResourcesIncrement [ResourceMax]int64
func IncrementUniform ¶
func IncrementUniform(nb int64) (rc ResourcesIncrement)
func (*ResourcesIncrement) SetValue ¶
func (ri *ResourcesIncrement) SetValue(v int64)
type ResourcesMultiplier ¶
type ResourcesMultiplier [ResourceMax]float64
func MultiplierUniform ¶
func MultiplierUniform(nb float64) (rc ResourcesMultiplier)
func (*ResourcesMultiplier) SetValue ¶
func (rm *ResourcesMultiplier) SetValue(v float64)
type SetOfArmies ¶
type SetOfArmies []*Army
func (*SetOfArmies) Add ¶
func (s *SetOfArmies) Add(a *Army)
func (SetOfArmies) Check ¶
func (s SetOfArmies) Check() error
func (SetOfArmies) CheckThenFail ¶
func (s SetOfArmies) CheckThenFail()
func (SetOfArmies) Get ¶
func (s SetOfArmies) Get(id string) *Army
func (SetOfArmies) Has ¶
func (s SetOfArmies) Has(id string) bool
func (SetOfArmies) Len ¶
func (s SetOfArmies) Len() int
func (SetOfArmies) Less ¶
func (s SetOfArmies) Less(i, j int) bool
func (*SetOfArmies) Remove ¶
func (s *SetOfArmies) Remove(a *Army)
func (*SetOfArmies) RemovePK ¶
func (s *SetOfArmies) RemovePK(pk string)
func (SetOfArmies) Swap ¶
func (s SetOfArmies) Swap(i, j int)
type SetOfArtifacts ¶
type SetOfArtifacts []*Artifact
func (*SetOfArtifacts) Add ¶
func (s *SetOfArtifacts) Add(a *Artifact)
func (SetOfArtifacts) Check ¶
func (s SetOfArtifacts) Check() error
func (SetOfArtifacts) CheckThenFail ¶
func (s SetOfArtifacts) CheckThenFail()
func (SetOfArtifacts) Get ¶
func (s SetOfArtifacts) Get(id string) *Artifact
func (SetOfArtifacts) Has ¶
func (s SetOfArtifacts) Has(id string) bool
func (SetOfArtifacts) Len ¶
func (s SetOfArtifacts) Len() int
func (SetOfArtifacts) Less ¶
func (s SetOfArtifacts) Less(i, j int) bool
func (*SetOfArtifacts) Remove ¶
func (s *SetOfArtifacts) Remove(a *Artifact)
func (*SetOfArtifacts) RemovePK ¶
func (s *SetOfArtifacts) RemovePK(pk string)
func (SetOfArtifacts) Swap ¶
func (s SetOfArtifacts) Swap(i, j int)
type SetOfBuildingTypes ¶
type SetOfBuildingTypes []*BuildingType
func (*SetOfBuildingTypes) Add ¶
func (s *SetOfBuildingTypes) Add(a *BuildingType)
func (SetOfBuildingTypes) Check ¶
func (s SetOfBuildingTypes) Check() error
func (SetOfBuildingTypes) CheckThenFail ¶
func (s SetOfBuildingTypes) CheckThenFail()
func (SetOfBuildingTypes) Frontier ¶
func (s SetOfBuildingTypes) Frontier(pop int64, built []*Building, owned []*Skill) []*BuildingType
func (SetOfBuildingTypes) Get ¶
func (s SetOfBuildingTypes) Get(id string) *BuildingType
func (SetOfBuildingTypes) Has ¶
func (s SetOfBuildingTypes) Has(id string) bool
func (SetOfBuildingTypes) Len ¶
func (s SetOfBuildingTypes) Len() int
func (SetOfBuildingTypes) Less ¶
func (s SetOfBuildingTypes) Less(i, j int) bool
func (*SetOfBuildingTypes) Remove ¶
func (s *SetOfBuildingTypes) Remove(a *BuildingType)
func (*SetOfBuildingTypes) RemovePK ¶
func (s *SetOfBuildingTypes) RemovePK(pk string)
func (SetOfBuildingTypes) Slice ¶
func (s SetOfBuildingTypes) Slice(marker string, max uint32) []*BuildingType
func (SetOfBuildingTypes) Swap ¶
func (s SetOfBuildingTypes) Swap(i, j int)
type SetOfBuildings ¶
type SetOfBuildings []*Building
func (*SetOfBuildings) Add ¶
func (s *SetOfBuildings) Add(a *Building)
func (SetOfBuildings) Check ¶
func (s SetOfBuildings) Check() error
func (SetOfBuildings) CheckThenFail ¶
func (s SetOfBuildings) CheckThenFail()
func (SetOfBuildings) Get ¶
func (s SetOfBuildings) Get(id string) *Building
func (SetOfBuildings) Has ¶
func (s SetOfBuildings) Has(id string) bool
func (SetOfBuildings) Len ¶
func (s SetOfBuildings) Len() int
func (SetOfBuildings) Less ¶
func (s SetOfBuildings) Less(i, j int) bool
func (*SetOfBuildings) Remove ¶
func (s *SetOfBuildings) Remove(a *Building)
func (*SetOfBuildings) RemovePK ¶
func (s *SetOfBuildings) RemovePK(pk string)
func (SetOfBuildings) Swap ¶
func (s SetOfBuildings) Swap(i, j int)
type SetOfCities ¶
type SetOfCities []*City
func (*SetOfCities) Add ¶
func (s *SetOfCities) Add(a *City)
func (SetOfCities) Check ¶
func (s SetOfCities) Check() error
func (SetOfCities) CheckThenFail ¶
func (s SetOfCities) CheckThenFail()
func (SetOfCities) Get ¶
func (s SetOfCities) Get(id uint64) *City
func (SetOfCities) Has ¶
func (s SetOfCities) Has(id uint64) bool
func (SetOfCities) Len ¶
func (s SetOfCities) Len() int
func (SetOfCities) Less ¶
func (s SetOfCities) Less(i, j int) bool
func (*SetOfCities) Remove ¶
func (s *SetOfCities) Remove(a *City)
func (*SetOfCities) RemovePK ¶
func (s *SetOfCities) RemovePK(pk uint64)
func (SetOfCities) Swap ¶
func (s SetOfCities) Swap(i, j int)
type SetOfFights ¶
type SetOfFights []*Fight
func (*SetOfFights) Add ¶
func (s *SetOfFights) Add(f *Fight)
func (SetOfFights) First ¶
func (s SetOfFights) First(cell uint64) int
func (SetOfFights) Len ¶
func (s SetOfFights) Len() int
func (SetOfFights) Less ¶
func (s SetOfFights) Less(i, j int) bool
func (SetOfFights) SliceByCell ¶
func (s SetOfFights) SliceByCell(cell uint64) []*Fight
func (SetOfFights) Swap ¶
func (s SetOfFights) Swap(i, j int)
type SetOfId ¶
type SetOfId []uint64
func (SetOfId) CheckThenFail ¶
func (s SetOfId) CheckThenFail()
type SetOfRegions ¶
type SetOfRegions []*Region
func (*SetOfRegions) Add ¶
func (s *SetOfRegions) Add(a *Region)
func (SetOfRegions) Check ¶
func (s SetOfRegions) Check() error
func (SetOfRegions) CheckThenFail ¶
func (s SetOfRegions) CheckThenFail()
func (SetOfRegions) Get ¶
func (s SetOfRegions) Get(id string) *Region
func (SetOfRegions) Has ¶
func (s SetOfRegions) Has(id string) bool
func (SetOfRegions) Len ¶
func (s SetOfRegions) Len() int
func (SetOfRegions) Less ¶
func (s SetOfRegions) Less(i, j int) bool
func (*SetOfRegions) Remove ¶
func (s *SetOfRegions) Remove(a *Region)
func (*SetOfRegions) RemovePK ¶
func (s *SetOfRegions) RemovePK(pk string)
func (SetOfRegions) Swap ¶
func (s SetOfRegions) Swap(i, j int)
type SetOfSkillTypes ¶
type SetOfSkillTypes []*SkillType
func (*SetOfSkillTypes) Add ¶
func (s *SetOfSkillTypes) Add(a *SkillType)
func (SetOfSkillTypes) Check ¶
func (s SetOfSkillTypes) Check() error
func (SetOfSkillTypes) CheckThenFail ¶
func (s SetOfSkillTypes) CheckThenFail()
func (SetOfSkillTypes) Frontier ¶
func (s SetOfSkillTypes) Frontier(owned []*Skill) []*SkillType
TODO(jfs): Maybe speed the execution with a reverse index of Requires
func (SetOfSkillTypes) Get ¶
func (s SetOfSkillTypes) Get(id string) *SkillType
func (SetOfSkillTypes) Has ¶
func (s SetOfSkillTypes) Has(id string) bool
func (SetOfSkillTypes) Len ¶
func (s SetOfSkillTypes) Len() int
func (SetOfSkillTypes) Less ¶
func (s SetOfSkillTypes) Less(i, j int) bool
func (*SetOfSkillTypes) Remove ¶
func (s *SetOfSkillTypes) Remove(a *SkillType)
func (*SetOfSkillTypes) RemovePK ¶
func (s *SetOfSkillTypes) RemovePK(pk string)
func (SetOfSkillTypes) Slice ¶
func (s SetOfSkillTypes) Slice(marker string, max uint32) []*SkillType
func (SetOfSkillTypes) Swap ¶
func (s SetOfSkillTypes) Swap(i, j int)
type SetOfSkills ¶
type SetOfSkills []*Skill
func (*SetOfSkills) Add ¶
func (s *SetOfSkills) Add(a *Skill)
func (SetOfSkills) Check ¶
func (s SetOfSkills) Check() error
func (SetOfSkills) CheckThenFail ¶
func (s SetOfSkills) CheckThenFail()
func (SetOfSkills) Get ¶
func (s SetOfSkills) Get(id string) *Skill
func (SetOfSkills) Has ¶
func (s SetOfSkills) Has(id string) bool
func (SetOfSkills) Len ¶
func (s SetOfSkills) Len() int
func (SetOfSkills) Less ¶
func (s SetOfSkills) Less(i, j int) bool
func (*SetOfSkills) Remove ¶
func (s *SetOfSkills) Remove(a *Skill)
func (*SetOfSkills) RemovePK ¶
func (s *SetOfSkills) RemovePK(pk string)
func (SetOfSkills) Swap ¶
func (s SetOfSkills) Swap(i, j int)
type SetOfTemplates ¶
type SetOfTemplates []*City
func (*SetOfTemplates) Add ¶
func (s *SetOfTemplates) Add(a *City)
func (SetOfTemplates) Check ¶
func (s SetOfTemplates) Check() error
func (SetOfTemplates) CheckThenFail ¶
func (s SetOfTemplates) CheckThenFail()
func (SetOfTemplates) Get ¶
func (s SetOfTemplates) Get(id string) *City
func (SetOfTemplates) Has ¶
func (s SetOfTemplates) Has(id string) bool
func (SetOfTemplates) Len ¶
func (s SetOfTemplates) Len() int
func (SetOfTemplates) Less ¶
func (s SetOfTemplates) Less(i, j int) bool
func (*SetOfTemplates) Remove ¶
func (s *SetOfTemplates) Remove(a *City)
func (*SetOfTemplates) RemovePK ¶
func (s *SetOfTemplates) RemovePK(pk string)
func (SetOfTemplates) Swap ¶
func (s SetOfTemplates) Swap(i, j int)
type SetOfUnitTypes ¶
type SetOfUnitTypes []*UnitType
func (*SetOfUnitTypes) Add ¶
func (s *SetOfUnitTypes) Add(a *UnitType)
func (SetOfUnitTypes) Check ¶
func (s SetOfUnitTypes) Check() error
func (SetOfUnitTypes) CheckThenFail ¶
func (s SetOfUnitTypes) CheckThenFail()
func (SetOfUnitTypes) Frontier ¶
func (s SetOfUnitTypes) Frontier(owned []*Building) []*UnitType
func (SetOfUnitTypes) Get ¶
func (s SetOfUnitTypes) Get(id string) *UnitType
func (SetOfUnitTypes) Has ¶
func (s SetOfUnitTypes) Has(id string) bool
func (SetOfUnitTypes) Len ¶
func (s SetOfUnitTypes) Len() int
func (SetOfUnitTypes) Less ¶
func (s SetOfUnitTypes) Less(i, j int) bool
func (*SetOfUnitTypes) Remove ¶
func (s *SetOfUnitTypes) Remove(a *UnitType)
func (*SetOfUnitTypes) RemovePK ¶
func (s *SetOfUnitTypes) RemovePK(pk string)
func (SetOfUnitTypes) Swap ¶
func (s SetOfUnitTypes) Swap(i, j int)
type SetOfUnits ¶
type SetOfUnits []*Unit
func (*SetOfUnits) Add ¶
func (s *SetOfUnits) Add(a *Unit)
func (SetOfUnits) Check ¶
func (s SetOfUnits) Check() error
func (SetOfUnits) CheckThenFail ¶
func (s SetOfUnits) CheckThenFail()
func (SetOfUnits) Get ¶
func (s SetOfUnits) Get(id string) *Unit
func (SetOfUnits) Has ¶
func (s SetOfUnits) Has(id string) bool
func (SetOfUnits) Len ¶
func (s SetOfUnits) Len() int
func (SetOfUnits) Less ¶
func (s SetOfUnits) Less(i, j int) bool
func (*SetOfUnits) Remove ¶
func (s *SetOfUnits) Remove(a *Unit)
func (*SetOfUnits) RemovePK ¶
func (s *SetOfUnits) RemovePK(pk string)
func (SetOfUnits) Swap ¶
func (s SetOfUnits) Swap(i, j int)
type SkillType ¶
type SkillType struct { ID string `json:"Id"` Name string `json:"Name"` Ticks uint32 `json:",omitempty"` // Transient bonus of Popularity, when the Skill is present PopBonus int64 // Permanent bonus of Popularity when the Skill is achieved PopBonusLearn int64 // Permanent bonus of Popularity (to the owner) when the Skill is stolen PopBonusStealVictim int64 // Permanent bonus of Popularity (to the robber) when the Skill is stolen PopBonusStealActor int64 // Impact of the current Building on the total storage capacity of the City. Stock ResourceModifiers // Increment of resources produced by this building. Prod ResourceModifiers // Amount of resources spent when the City starts learning this skill Cost0 Resources // Amount of resources spent to advance of one tick Cost Resources // All the skills that are required to start the current Skill // (this is an AND, not an OR) Requires []string // All the skill that are forbidden by the current skill Conflicts []string }
type Unit ¶
type Unit struct { // Unique ID of the Unit ID string `json:"Id"` // A copy of the definition for the current Unit. Type string `json:"idtype"` // How many ticks remain before the Troop training is finished Ticks uint32 // The number of health points of the unit, Health should be less or equal to HealthMax Health uint32 `json:"H,omitempty"` }
Unit is the part of an Army that can participate to a Fight. A Unit is owned after a training period. It has a regular cost.
type UnitType ¶
type UnitType struct { // Unique ID of the Unit Type ID string `json:"Id"` // The number of health point for that type of unit. // A health equal to 0 means the death of the unit. Health uint32 // How affected is that type of unit by a loss of Health. // Must be between 0 and 1. // 0 means that the capacity of the Unit isn't affected by a health reduction. // 1 means that the capacity of the Unit loses an equal percentage of its capacity // for a loss of health (in other words, a HealthFactor of 1 means that the Unit // will hit at 90% of its maximal power if it has 90% of its health points). HealthFactor float64 // The display name of the Unit Type Name string // How many ticks Ticks uint32 // Transient bonus of Popularity, when the Unit is alive PopBonus int64 // Permanent bonus of Popularity given when the Unit's training is done PopBonusTrain int64 // Permanent bonus of Popularity given to the owner of the Unit when it dies PopBonusDeath int64 // Permanent bonus of Popularity given to the killer of the Unit PopBonusKill int64 // Permanent bonus of Popularity given to the ownerof the Unit when it is disbanded. PopBonusDisband int64 // Instantiation cost of the current UnitType at the beginning of the process Cost0 Resources // Instantiation cost of the current UnitType, at each step of the process. Cost Resources // Might positive (resource boost) or more commonly negative (maintenance cost) Prod ResourceModifiers // Required Popularity to start training this type of troop ReqPop int64 // A UnitType is only dependant on the presence of a Building of that BuildingType. RequiredBuilding string }
UnitType gathers the core statistics of a kind of Unit. It actually dictates the behavior of the Unit.
type World ¶
type World struct { // Core configuration common to all the Regions of the current World. Config Configuration // Data that define the current World, shared among all the Regions. Definitions DefinitionsBase // All the regions that have been instantiated into the current World. Regions SetOfRegions // contains filtered or unexported fields }
func (*World) BuildingGetFrontier ¶
func (w *World) BuildingGetFrontier(pop int64, built []*Building, owned []*Skill) []*BuildingType
func (*World) BuildingTypeGet ¶
func (w *World) BuildingTypeGet(id string) *BuildingType
func (*World) CreateRegion ¶
CreateRegion instantiates and registers a Region into the current World. There is no check that the map exists! There is no check that the set of City exist on the map!
func (*World) LoadDefinitions ¶
func (*World) LoadRegions ¶
func (*World) RLock ¶
func (w *World) RLock()
RLock acquires a shared("reader") lock on the current world Several requests for a reader's lock may be granted simultaneously but they are incompatible with any writer's locks. Their usage is reserved for read-nonly operations.
func (*World) RUnlock ¶
func (w *World) RUnlock()
RUnlock releases a shared("reader") lock on the current world
func (*World) SetMapClient ¶
SetMapClient changes the MapClient associated to the current World. that MapClient will further be used for paths resolution before armies movements
func (*World) SetNotifier ¶
SetNotifier changes the event Notifier associated with the current World. That Notifier is used for in-game notifications, to collect a per-Character log.