weapons.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. type Gun struct {
  7. node *Node
  8. Pos Vec2
  9. Mount string // might be empty for no mount
  10. Over bool // false=under, true=over
  11. }
  12. func (g *Gun) Parse(node *Node) error {
  13. if node.Key() != "gun" {
  14. return fmt.Errorf("not a gun")
  15. }
  16. g.node = node
  17. g.Pos.Parse(node.Line)
  18. work := strings.Split(node.Value(), " ")
  19. if len(work) >= 3 {
  20. g.Mount = strings.Join(work[3:], " ")
  21. }
  22. if node.Len() != 0 {
  23. for _, kid := range node.Children {
  24. switch kid.Key() {
  25. case "over":
  26. g.Over = true
  27. }
  28. }
  29. }
  30. return nil
  31. }
  32. type Turret struct {
  33. node *Node
  34. Pos Vec2
  35. Mount string // might be empty for no mount
  36. Over bool // false=under, true=over
  37. }
  38. func (t *Turret) Parse(node *Node) error {
  39. if node.Key() != "turret" {
  40. return fmt.Errorf("not a turret")
  41. }
  42. t.node = node
  43. t.Pos.Parse(node.Line)
  44. work := strings.Split(node.Value(), " ")
  45. if len(work) >= 3 {
  46. t.Mount = strings.Join(work[3:], " ")
  47. }
  48. if node.Len() != 0 {
  49. for _, kid := range node.Children {
  50. switch kid.Key() {
  51. case "over":
  52. t.Over = true
  53. }
  54. }
  55. }
  56. return nil
  57. }