region

package
v0.0.0-...-2bb1cf3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceActions   = iota
	ResourceGold      = iota
	ResourceCereal    = iota
	ResourceLivestock = iota
	ResourceStone     = iota
	ResourceWood      = iota
	ResourceMax       = iota
)
View Source
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"
)
View Source
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 (a *Army) ApplyAgressivity(w *Region)

func (*Army) BreakBuilding

func (a *Army) BreakBuilding(w *Region, pCity *City)

func (*Army) Cancel

func (a *Army) Cancel(w *Region) error

func (*Army) Conquer

func (a *Army) Conquer(w *World, pCity *City)

func (*Army) DeferAttack

func (a *Army) DeferAttack(w *Region, loc uint64, args ActionArgAssault) error

func (*Army) DeferDefend

func (a *Army) DeferDefend(w *Region, loc uint64) error

func (*Army) DeferDisband

func (a *Army) DeferDisband(w *Region, loc uint64) error

func (*Army) DeferMove

func (a *Army) DeferMove(w *Region, loc uint64, args ActionArgMove) error

func (*Army) DeferWait

func (a *Army) DeferWait(w *Region, loc uint64) error

func (*Army) Deposit

func (a *Army) Deposit(w *Region, pCity *City)

func (*Army) Disband

func (a *Army) Disband(w *Region, pCity *City, shouldNotify bool)

func (*Army) Flea

func (a *Army) Flea(w *Region) error

Leave the Fight as a loser

func (*Army) Flip

func (a *Army) Flip(w *Region) error

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 (a *Army) JoinCityAttack(w *Region, pCity *City)

func (*Army) JoinCityDefence

func (a *Army) JoinCityDefence(w *Region, pCity *City) bool

func (*Army) Massacre

func (a *Army) Massacre(w *Region, pCity *City)

func (*Army) Move

func (a *Army) Move(ctx context.Context, r *Region)

func (*Army) PopCommand

func (a *Army) PopCommand()

type Artifact

type Artifact struct {
	// UUID
	ID string `json:"Id"`
	// UUID
	Type string
	// UUID
	Name    string
	Visible bool `json:"Visible,omitempty"`
}

type Building

type Building struct {
	// The unique ID of the current Building
	ID string `json:"Id"`

	// The unique ID of the BuildingType associated to the current Building
	Type string

	// How many construction rounds remain before the building's achievement
	Ticks uint32 `json:",omitempty"`
}

func (*Building) Finish

func (b *Building) Finish() *Building

Abruptly terminate the construction of the Building. The number of building ticks suddenly drop to 0, whatever its prior value.

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 MakeCity

func MakeCity() *City

func (*City) ApplyModel

func (c *City) ApplyModel(model *City)

func (*City) ApplyNamedModel

func (c *City) ApplyNamedModel(r *Region, modelName string) error

func (*City) Build

func (c *City) Build(w *Region, bID string) (string, error)

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

func (c *City) ComputePopularity(r *Region) int64

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

func (c *City) ComputeStats(r *Region) CityStats

ComputeStats computes the gauges and extract the counters to build a CityStats about the current City.

func (*City) ComputeStock

func (c *City) ComputeStock(r *Region) *CityStock

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 (c *City) ConquerCity(w *World, other *City)

func (*City) CreateArmyDefence

func (c *City) CreateArmyDefence(w *Region) (*Army, error)

Create an Army made of all the Units defending the City

func (*City) CreateArmyFromIds

func (c *City) CreateArmyFromIds(w *Region, ids ...string) (*Army, error)

Create an Army made of some Unit of the City

func (*City) CreateArmyFromUnit

func (c *City) CreateArmyFromUnit(w *Region, units ...*Unit) (*Army, error)

Create an Army made of some Unit of the City

func (*City) CreateEmptyArmy

func (c *City) CreateEmptyArmy(_ *Region) *Army

CreateEmptyArmy

func (*City) CreateTransport

func (c *City) CreateTransport(w *Region, r Resources) (*Army, error)

Create an Army carrying resources you own

func (*City) GainFreedom

func (c *City) GainFreedom(w *World)

func (*City) GetBuilding

func (c *City) GetBuilding(id string) *Building

GetBuilding returns a Building owned by the current City, given the Building ID

func (*City) GetLieges

func (c *City) GetLieges() []*City

GetLieges returns a list of all the Lieges of the current City.

func (*City) GetSkill

func (c *City) GetSkill(id string) *Skill

GetSkill returns a Skill owned by the current City, given the Skill ID

func (*City) GetUnit

func (c *City) GetUnit(id string) *Unit

GetUnit returns a Unit owned by the current City, given the Unit ID

func (*City) InstantBuild

func (c *City) InstantBuild(w *Region, bID string) error

Build forwards the call to StartBuilding if all the conditions are met, after the initial fee given in the BuildingType

func (*City) InstantStudy

func (c *City) InstantStudy(w *Region, typeID string) error

func (*City) InstantTrain

func (c *City) InstantTrain(w *Region, typeID string) error

func (*City) LiberateCity

func (c *City) LiberateCity(w *World, other *City)

func (*City) Produce

func (c *City) Produce(_ context.Context, w *Region)

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 (c *City) SendResourcesTo(w *Region, overlord *City, amount Resources) error

func (*City) SetTaxRate

func (c *City) SetTaxRate(m ResourcesMultiplier)

Set the given tax rate to the current City.

func (*City) SetUniformTaxRate

func (c *City) SetUniformTaxRate(nb float64)

Set a tax rate on the current City, with the same ratio on every Resource.

func (*City) SkillFrontier

func (c *City) SkillFrontier(w *Region) []*SkillType

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

func (c *City) StartStudy(pType *SkillType) *Skill

StartStudy declares a new Skill with the given type and the tick sgauge at its max

func (*City) StartUnit

func (c *City) StartUnit(w *Region, pType *UnitType) *Unit

Create a Unit of the given UnitType. No check is performed to verify the City has all the requirements.

func (*City) Study

func (c *City) Study(w *Region, typeID string) (string, error)

func (*City) Train

func (c *City) Train(w *Region, typeID string) (string, error)

Start the training of a Unit of the given UnitType (id). The whole chain of requirements will be checked.

func (*City) TransferOwnResources

func (c *City) TransferOwnResources(a *Army, r Resources) error

func (*City) TransferOwnUnit

func (c *City) TransferOwnUnit(a *Army, units ...string) error

func (*City) UnitAllowed

func (c *City) UnitAllowed(t *UnitType) bool

check the current City has all the requirements to train a Unti of the given UnitType.

func (*City) UnitFrontier

func (c *City) UnitFrontier(w *Region) []*UnitType

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 EventArmy

type EventArmy interface {
	Item(a *Army) EventArmy
	// Notify the movement
	Move(src, dst uint64) EventArmy
	// Notify the movement is not possible
	NoRoute(src, dst uint64) EventArmy
	Send()
}

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

func NewDirectMapClient

func NewDirectMapClient(_ context.Context) (MapClient, error)

NewDirectMapClient instantiates a Map client tat directly resolves the paths via the Map service returned by the utils.DefaultDiscovery.

type NamedCity

type NamedCity struct {
	Name string
	ID   uint64
}

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
}

func LogEvent

func LogEvent(n Notifier) Notifier

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) Check

func (reg *Region) Check() error

func (*Region) CityCreate

func (reg *Region) CityCreate(loc uint64) (*City, error)

func (*Region) CityGet

func (reg *Region) CityGet(id uint64) *City

func (*Region) GetCitiesByOwner

func (reg *Region) GetCitiesByOwner(idChar string) []*City

func (*Region) GetWorld

func (reg *Region) GetWorld() *World

func (*Region) Move

func (reg *Region) Move(ctx context.Context)

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.

func (*Region) PostLoad

func (reg *Region) PostLoad() error

func (*Region) Produce

func (reg *Region) Produce(ctx context.Context)

Produce performs a production round that involves 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.

func (*Region) UnitGet

func (reg *Region) UnitGet(city uint64, id string) *Unit

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

type Resources

type Resources [ResourceMax]uint64

func ResourcesUniform

func ResourcesUniform(nb uint64) (rc Resources)

func (*Resources) Add

func (r *Resources) Add(o Resources)

func (*Resources) Apply

func (r *Resources) Apply(rm ...ResourceModifiers)

func (Resources) Copy

func (r Resources) Copy() Resources

func (Resources) Equals

func (r Resources) Equals(o Resources) bool

func (Resources) GreaterOrEqualTo

func (r Resources) GreaterOrEqualTo(o Resources) bool

func (*Resources) Increment

func (r *Resources) Increment(ri ResourcesIncrement)

func (Resources) IsZero

func (r Resources) IsZero() bool

func (*Resources) Multiply

func (r *Resources) Multiply(rm ResourcesMultiplier)

func (*Resources) Remove

func (r *Resources) Remove(o Resources)

func (*Resources) Set

func (r *Resources) Set(o Resources)

func (*Resources) SetValue

func (r *Resources) SetValue(v uint64)

func (*Resources) TrimTo

func (r *Resources) TrimTo(limit Resources)

func (*Resources) Zero

func (r *Resources) Zero()

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) Slice

func (s SetOfArmies) Slice(marker string, max uint32) []*Army

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) Slice

func (s SetOfArtifacts) Slice(marker string, max uint32) []*Artifact

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 (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) Slice

func (s SetOfBuildings) Slice(marker string, max uint32) []*Building

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) Slice

func (s SetOfCities) Slice(marker uint64, max uint32) []*City

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) Add

func (s *SetOfId) Add(a uint64)

func (SetOfId) Check

func (s SetOfId) Check() error

func (SetOfId) CheckThenFail

func (s SetOfId) CheckThenFail()

func (SetOfId) Get

func (s SetOfId) Get(id uint64) uint64

func (SetOfId) Has

func (s SetOfId) Has(id uint64) bool

func (SetOfId) Len

func (s SetOfId) Len() int

func (SetOfId) Less

func (s SetOfId) Less(i, j int) bool

func (*SetOfId) Remove

func (s *SetOfId) Remove(a uint64)

func (*SetOfId) RemovePK

func (s *SetOfId) RemovePK(pk uint64)

func (SetOfId) Slice

func (s SetOfId) Slice(marker uint64, max uint32) []uint64

func (SetOfId) Swap

func (s SetOfId) Swap(i, j int)

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) Slice

func (s SetOfRegions) Slice(marker string, max uint32) []*Region

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) Slice

func (s SetOfSkills) Slice(marker string, max uint32) []*Skill

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) Slice

func (s SetOfTemplates) Slice(marker string, max uint32) []*City

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) Slice

func (s SetOfUnitTypes) Slice(marker string, max uint32) []*UnitType

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) Slice

func (s SetOfUnits) Slice(marker string, max uint32) []*Unit

func (SetOfUnits) Swap

func (s SetOfUnits) Swap(i, j int)

type Skill

type Skill struct {
	ID    string `json:"Id"`
	Type  string
	Ticks uint32 `json:"Ticks,omitempty"`
}

func (*Skill) Finish

func (k *Skill) Finish() *Skill

Finish abruptly terminates the study of the Skill. The number of study ticks suddenly drop to 0, whatever its prior value.

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.

func (*Unit) Finish

func (u *Unit) Finish() *Unit

Abruptly terminate the training of the Unit. The number of training ticks suddenly drop to 0, whatever its prior value.

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 NewWorld

func NewWorld() (*World, error)

NewWorld instantiates an empty World, free of any definition

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) Check

func (w *World) Check() error

func (*World) CreateRegion

func (w *World) CreateRegion(name, mapName string, cities []NamedCity) (*Region, error)

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 (w *World) LoadDefinitions(basedir string) (err error)

func (*World) LoadRegions

func (w *World) LoadRegions(basedir string) error

func (*World) PostLoad

func (w *World) PostLoad() error

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

func (w *World) SetMapClient(c MapClient)

SetMapClient changes the MapClient associated to the current World. that MapClient will further be used for paths resolution before armies movements

func (*World) SetNotifier

func (w *World) SetNotifier(n Notifier)

SetNotifier changes the event Notifier associated with the current World. That Notifier is used for in-game notifications, to collect a per-Character log.

func (*World) SkillGetFrontier

func (w *World) SkillGetFrontier(owned []*Skill) []*SkillType

func (*World) SkillTypeGet

func (w *World) SkillTypeGet(id string) *SkillType

func (*World) UnitGetFrontier

func (w *World) UnitGetFrontier(owned []*Building) []*UnitType

func (*World) UnitTypeGet

func (w *World) UnitTypeGet(id string) *UnitType

func (*World) WLock

func (w *World) WLock()

WLock acquires an exclusive ("writer") lock on the current world The request for a writer's lock has the priority on any equest for a reader's lock. It also forbid any concurrent writer or reader lock to be acquired.

func (*World) WUnlock

func (w *World) WUnlock()

WUnlock releases an exclusive ("writer") lock on the current world

Jump to

Keyboard shortcuts

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