server/robot.go

85 lines
1.9 KiB
Go
Raw Normal View History

2013-09-27 22:27:05 -07:00
package main
import (
v "bitbucket.org/hackerbots/vector"
)
type Robot struct {
Id string `json:"id"`
Name string `json:"name"`
Stats Stats `json:"stats"`
TargetSpeed float64 `json:"speed"`
Speed float64 `json:"speed"`
Health int `json:"health"`
Position v.Point2d `json:"position"`
Heading v.Vector2d `json:"heading"`
MoveTo *v.Point2d `json:"move_to,omitempty"`
FireAt *v.Point2d `json:"fire_at,omitempty"`
Scanners []Scanner `json:"scanners"`
}
type RobotSorter struct {
Robots []Robot
}
func (s RobotSorter) Len() int {
return len(s.Robots)
}
func (s RobotSorter) Swap(i, j int) {
s.Robots[i], s.Robots[j] = s.Robots[j], s.Robots[i]
}
func (s RobotSorter) Less(i, j int) bool {
return s.Robots[i].Id < s.Robots[j].Id
}
type Stats struct {
Hp int `json:"hp"`
Speed float64 `json:"speed"`
Acceleration float64 `json:"acceleration"`
WeaponRadius int `json:"weapon_radius"`
ScannerRadius int `json:"scanner_radius"`
}
func (s Stats) Valid() bool {
total := int(s.Speed) + s.Hp + s.WeaponRadius + s.ScannerRadius
if total > 500 {
return false
}
return true
}
type Projectile struct {
Id string `json:"id"`
Position v.Point2d `json:"position"`
MoveTo v.Point2d `json:"move_to"`
Radius int `json:"radius"`
Speed float64 `json:"speed"`
Damage int `json:"damage"`
}
type Splosion struct {
Id string `json:"id"`
Position v.Point2d `json:"position"`
Radius int `json:"radius"`
MaxDamage int `json:"damage"`
MinDamage int `json:"damage"`
Lifespan int `json:"lifespan"`
}
func (s *Splosion) Tick() {
s.Lifespan--
}
func (s *Splosion) Alive() bool {
return s.Lifespan > 0
}
type Instruction struct {
MoveTo *v.Point2d `json:"move_to,omitempty"`
FireAt *v.Point2d `json:"fire_at,omitempty"`
Stats Stats `json:"stats"`
}