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:
parent
cc248dc2fe
commit
de68ec2e7b
25
game.go
25
game.go
@ -18,7 +18,8 @@ type BotHealth struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Boardstate struct {
|
type Boardstate struct {
|
||||||
Robots []Robot `json:"robots"`
|
MyRobots []Robot `json:"my_robots"`
|
||||||
|
OtherRobots []OtherRobot `json:"robots"`
|
||||||
Projectiles []Projectile `json:"projectiles"`
|
Projectiles []Projectile `json:"projectiles"`
|
||||||
Splosions []Splosion `json:"splosions"`
|
Splosions []Splosion `json:"splosions"`
|
||||||
Reset bool `json:"reset"`
|
Reset bool `json:"reset"`
|
||||||
@ -29,7 +30,8 @@ type Boardstate struct {
|
|||||||
|
|
||||||
func NewBoardstate() *Boardstate {
|
func NewBoardstate() *Boardstate {
|
||||||
return &Boardstate{
|
return &Boardstate{
|
||||||
Robots: []Robot{},
|
MyRobots: []Robot{},
|
||||||
|
OtherRobots: []OtherRobot{},
|
||||||
Projectiles: []Projectile{},
|
Projectiles: []Projectile{},
|
||||||
Splosions: []Splosion{},
|
Splosions: []Splosion{},
|
||||||
AllBots: []BotHealth{},
|
AllBots: []BotHealth{},
|
||||||
@ -40,7 +42,7 @@ func NewBoardstate() *Boardstate {
|
|||||||
type Scanner struct {
|
type Scanner struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Position v.Point2d `json:"position"`
|
Position v.Point2d `json:"position"`
|
||||||
Stats Stats `json:"stats"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MapLock struct {
|
type MapLock struct {
|
||||||
@ -121,7 +123,9 @@ func (g *game) tick(payload *Boardstate) int {
|
|||||||
robots_remaining++
|
robots_remaining++
|
||||||
p.Tick(g)
|
p.Tick(g)
|
||||||
}
|
}
|
||||||
payload.Robots = append(payload.Robots, p.Robot)
|
payload.OtherRobots = append(
|
||||||
|
payload.OtherRobots,
|
||||||
|
p.Robot.GetTruncatedDetails())
|
||||||
|
|
||||||
payload.AllBots = append(
|
payload.AllBots = append(
|
||||||
payload.AllBots,
|
payload.AllBots,
|
||||||
@ -152,7 +156,7 @@ func (g *game) tick(payload *Boardstate) int {
|
|||||||
|
|
||||||
func (g *game) send_update(payload *Boardstate) {
|
func (g *game) send_update(payload *Boardstate) {
|
||||||
// Ensure that the robots are always sent in a consistent order
|
// 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 {
|
for p := range g.players {
|
||||||
// Copy the payload but only add the robots in scanner range
|
// 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.AllBots = payload.AllBots
|
||||||
player_payload.Turn = payload.Turn
|
player_payload.Turn = payload.Turn
|
||||||
player_payload.Reset = payload.Reset
|
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 {
|
if p.Robot.Health > 0 {
|
||||||
for player := range g.players {
|
for player := range g.players {
|
||||||
for _, scan_entry := range p.Robot.Scanners {
|
for _, scan_entry := range p.Robot.Scanners {
|
||||||
if player.Robot.Id == scan_entry.Id {
|
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 {
|
} else {
|
||||||
player_payload.Robots = payload.Robots
|
player_payload.OtherRobots = payload.OtherRobots
|
||||||
}
|
}
|
||||||
|
|
||||||
// x, _ := json.Marshal(player_payload)
|
// x, _ := json.Marshal(player_payload)
|
||||||
|
@ -71,7 +71,6 @@ func (p *player) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check Other Bots
|
// Check Other Bots
|
||||||
// TODO - FIX THIS
|
|
||||||
for player := range g.players {
|
for player := range g.players {
|
||||||
if player.Robot.Id == p.Robot.Id {
|
if player.Robot.Id == p.Robot.Id {
|
||||||
continue
|
continue
|
||||||
|
20
robot.go
20
robot.go
@ -19,8 +19,26 @@ type Robot struct {
|
|||||||
LastFired int `json:"-"`
|
LastFired int `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is the subset of data we send to players about robots
|
||||||
|
// that are not theirs.
|
||||||
|
type OtherRobot struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Position v.Point2d `json:"position"`
|
||||||
|
Health int `json:"health"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Robot) GetTruncatedDetails() OtherRobot {
|
||||||
|
return OtherRobot{
|
||||||
|
Id: r.Id,
|
||||||
|
Name: r.Name,
|
||||||
|
Position: r.Position,
|
||||||
|
Health: r.Health,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type RobotSorter struct {
|
type RobotSorter struct {
|
||||||
Robots []Robot
|
Robots []OtherRobot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s RobotSorter) Len() int {
|
func (s RobotSorter) Len() int {
|
||||||
|
Loading…
Reference in New Issue
Block a user