feat: voting procedures
This commit is contained in:
@@ -29,19 +29,20 @@ type Game struct {
|
||||
Age uint `json:"turn"` // Game's turn number
|
||||
Map Map `json:"map"`
|
||||
Race []Race `json:"races"`
|
||||
Votes float64 `json:"votes"`
|
||||
ShipGroups []ShipGroup `json:"shipGroup,omitempty"`
|
||||
Fleets []Fleet `json:"fleet,omitempty"`
|
||||
}
|
||||
|
||||
func (g Game) Votes(raceID uuid.UUID) float64 {
|
||||
// XXX: calculate [Race]Population once when loading Game from Storage?
|
||||
var pop float64
|
||||
// TODO: remove if not needed
|
||||
func (g Game) RaceVotes(raceID uuid.UUID) float64 {
|
||||
var result float64
|
||||
for i := range g.Map.Planet {
|
||||
if g.Map.Planet[i].Owner == raceID {
|
||||
pop += g.Map.Planet[i].Population
|
||||
result += g.Map.Planet[i].Votes()
|
||||
}
|
||||
}
|
||||
return pop / 1000.
|
||||
return result
|
||||
}
|
||||
|
||||
func (g Game) MarshalBinary() (data []byte, err error) {
|
||||
|
||||
@@ -41,6 +41,10 @@ type PlanetReportForeign struct {
|
||||
PlanetReport
|
||||
}
|
||||
|
||||
func (p Planet) Votes() float64 {
|
||||
return p.Population / 1000.
|
||||
}
|
||||
|
||||
// Производственный потенциал
|
||||
func (p Planet) ProductionCapacity() float64 {
|
||||
return PlanetProduction(p.Industry, p.Population)
|
||||
|
||||
@@ -7,7 +7,8 @@ type Race struct {
|
||||
Name string `json:"name"`
|
||||
Extinct bool `json:"extinct"`
|
||||
|
||||
Vote uuid.UUID `json:"vote"`
|
||||
Votes float64 `json:"votes"`
|
||||
VoteFor uuid.UUID `json:"voteFor"`
|
||||
Relations []RaceRelation `json:"relations"`
|
||||
|
||||
Tech TechSet `json:"tech"`
|
||||
|
||||
Reference in New Issue
Block a user