player messages

This commit is contained in:
Fraser Graham 2013-11-07 22:10:18 -08:00
parent 1b42a19393
commit 164c37e7d6

10
game.go
View File

@ -26,6 +26,7 @@ type Boardstate struct {
Type string `json:"type"` Type string `json:"type"`
Turn int `json:"turn"` Turn int `json:"turn"`
AllBots []BotHealth `json:"all_bots"` AllBots []BotHealth `json:"all_bots"`
Messages []string `json:"messages"`
} }
func NewBoardstate() *Boardstate { func NewBoardstate() *Boardstate {
@ -130,6 +131,14 @@ func (g *game) tick(payload *Boardstate) int {
robots_remaining++ robots_remaining++
p.Tick(g) p.Tick(g)
} }
if len(p.Robot.Message) > 0 {
if len(p.Robot.Message) > 100 {
p.Robot.Message = p.Robot.Message[0:99]
}
payload.Messages = append(payload.Messages, p.Robot.Message)
}
payload.OtherRobots = append( payload.OtherRobots = append(
payload.OtherRobots, payload.OtherRobots,
p.Robot.GetTruncatedDetails()) p.Robot.GetTruncatedDetails())
@ -169,6 +178,7 @@ func (g *game) send_update(payload *Boardstate) {
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
player_payload := NewBoardstate() player_payload := NewBoardstate()
player_payload.Messages = payload.Messages
player_payload.Splosions = payload.Splosions player_payload.Splosions = payload.Splosions
player_payload.Obstacles = payload.Obstacles player_payload.Obstacles = payload.Obstacles
player_payload.AllBots = payload.AllBots player_payload.AllBots = payload.AllBots