Create a stripped down version of the robot struct to represent all robots and break up the update into my_robots and robots.
Has dependent change on client
This commit is contained in:
@@ -18,7 +18,8 @@ type BotHealth struct {
|
||||
}
|
||||
|
||||
type Boardstate struct {
|
||||
Robots []Robot `json:"robots"`
|
||||
MyRobots []Robot `json:"my_robots"`
|
||||
OtherRobots []OtherRobot `json:"robots"`
|
||||
Projectiles []Projectile `json:"projectiles"`
|
||||
Splosions []Splosion `json:"splosions"`
|
||||
Reset bool `json:"reset"`
|
||||
@@ -29,7 +30,8 @@ type Boardstate struct {
|
||||
|
||||
func NewBoardstate() *Boardstate {
|
||||
return &Boardstate{
|
||||
Robots: []Robot{},
|
||||
MyRobots: []Robot{},
|
||||
OtherRobots: []OtherRobot{},
|
||||
Projectiles: []Projectile{},
|
||||
Splosions: []Splosion{},
|
||||
AllBots: []BotHealth{},
|
||||
@@ -40,7 +42,7 @@ func NewBoardstate() *Boardstate {
|
||||
type Scanner struct {
|
||||
Id string `json:"id"`
|
||||
Position v.Point2d `json:"position"`
|
||||
Stats Stats `json:"stats"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type MapLock struct {
|
||||
@@ -121,7 +123,9 @@ func (g *game) tick(payload *Boardstate) int {
|
||||
robots_remaining++
|
||||
p.Tick(g)
|
||||
}
|
||||
payload.Robots = append(payload.Robots, p.Robot)
|
||||
payload.OtherRobots = append(
|
||||
payload.OtherRobots,
|
||||
p.Robot.GetTruncatedDetails())
|
||||
|
||||
payload.AllBots = append(
|
||||
payload.AllBots,
|
||||
@@ -152,7 +156,7 @@ func (g *game) tick(payload *Boardstate) int {
|
||||
|
||||
func (g *game) send_update(payload *Boardstate) {
|
||||
// Ensure that the robots are always sent in a consistent order
|
||||
sort.Sort(RobotSorter{Robots: payload.Robots})
|
||||
sort.Sort(RobotSorter{Robots: payload.OtherRobots})
|
||||
|
||||
for p := range g.players {
|
||||
// Copy the payload but only add the robots in scanner range
|
||||
@@ -162,18 +166,23 @@ func (g *game) send_update(payload *Boardstate) {
|
||||
player_payload.AllBots = payload.AllBots
|
||||
player_payload.Turn = payload.Turn
|
||||
player_payload.Reset = payload.Reset
|
||||
player_payload.Robots = append(player_payload.Robots, p.Robot)
|
||||
player_payload.MyRobots = append(player_payload.MyRobots, p.Robot)
|
||||
player_payload.OtherRobots = append(
|
||||
player_payload.OtherRobots,
|
||||
p.Robot.GetTruncatedDetails())
|
||||
|
||||
if p.Robot.Health > 0 {
|
||||
for player := range g.players {
|
||||
for _, scan_entry := range p.Robot.Scanners {
|
||||
if player.Robot.Id == scan_entry.Id {
|
||||
player_payload.Robots = append(player_payload.Robots, player.Robot)
|
||||
player_payload.OtherRobots = append(
|
||||
player_payload.OtherRobots,
|
||||
player.Robot.GetTruncatedDetails())
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player_payload.Robots = payload.Robots
|
||||
player_payload.OtherRobots = payload.OtherRobots
|
||||
}
|
||||
|
||||
// x, _ := json.Marshal(player_payload)
|
||||
|
||||
Reference in New Issue
Block a user