Allow number to be used in all commands

This commit is contained in:
Marc Di Luzio 2020-07-26 17:19:04 +01:00
parent bcf71f0bf9
commit 1514603517
3 changed files with 40 additions and 57 deletions

View file

@ -717,50 +717,31 @@ func (w *World) Tick() {
func (w *World) ExecuteCommand(c *roveapi.Command, rover string) (done bool, err error) { func (w *World) ExecuteCommand(c *roveapi.Command, rover string) (done bool, err error) {
log.Printf("Executing command: %+v for %s\n", c.Command, rover) log.Printf("Executing command: %+v for %s\n", c.Command, rover)
// Decrement the number of the command
c.Number--
switch c.Command { switch c.Command {
case roveapi.CommandType_toggle: case roveapi.CommandType_toggle:
if _, err := w.RoverToggle(rover); err != nil { _, err = w.RoverToggle(rover)
return true, err
}
case roveapi.CommandType_stash: case roveapi.CommandType_stash:
if _, err := w.RoverStash(rover); err != nil { _, err = w.RoverStash(rover)
return true, err
}
case roveapi.CommandType_repair: case roveapi.CommandType_repair:
if _, err := w.RoverRepair(rover); err != nil { _, err = w.RoverRepair(rover)
return true, err
}
case roveapi.CommandType_broadcast: case roveapi.CommandType_broadcast:
if err := w.RoverBroadcast(rover, c.GetData()); err != nil { err = w.RoverBroadcast(rover, c.GetData())
return true, err
}
case roveapi.CommandType_turn: case roveapi.CommandType_turn:
if _, err := w.RoverTurn(rover, c.GetBearing()); err != nil { _, err = w.RoverTurn(rover, c.GetBearing())
return true, err
}
case roveapi.CommandType_salvage: case roveapi.CommandType_salvage:
if _, err := w.RoverSalvage(rover); err != nil { _, err = w.RoverSalvage(rover)
return true, err
}
case roveapi.CommandType_transfer: case roveapi.CommandType_transfer:
if _, err := w.RoverTransfer(rover); err != nil { _, err = w.RoverTransfer(rover)
return true, err
}
case roveapi.CommandType_wait: case roveapi.CommandType_wait:
c.Number-- // Nothing to do
return c.Number == 0, nil
default: default:
return true, fmt.Errorf("unknown command: %s", c.Command) return true, fmt.Errorf("unknown command: %s", c.Command)
} }
return return c.Number <= 0, err
} }
// Daytime returns if it's currently daytime // Daytime returns if it's currently daytime

View file

@ -53,7 +53,7 @@ const (
CommandType_salvage CommandType = 6 CommandType_salvage CommandType = 6
// Transfers remote control into dormant rover // Transfers remote control into dormant rover
CommandType_transfer CommandType = 7 CommandType_transfer CommandType = 7
// Waits for the specified number of server ticks (requires number) // Waits before performing the next command
CommandType_wait CommandType = 8 CommandType_wait CommandType = 8
) )
@ -193,7 +193,8 @@ const (
Object_RockSmall Object = 3 Object_RockSmall Object = 3
// RockLarge is a large blocking rock // RockLarge is a large blocking rock
Object_RockLarge Object = 4 Object_RockLarge Object = 4
// RoverParts is one unit of rover parts, used for repairing and fixing the rover // RoverParts is one unit of rover parts, used for repairing and fixing the
// rover
Object_RoverParts Object = 5 Object_RoverParts Object = 5
) )
@ -640,12 +641,13 @@ type Command struct {
// The command type // The command type
Command CommandType `protobuf:"varint,1,opt,name=command,proto3,enum=roveapi.CommandType" json:"command,omitempty"` Command CommandType `protobuf:"varint,1,opt,name=command,proto3,enum=roveapi.CommandType" json:"command,omitempty"`
// broadcast - a simple message, must be composed of up to 3 printable ASCII glyphs (32-126) // The number of times to execute the command (assumes 1 if not present or 0)
Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` Number int32 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"`
// broadcast - a simple message, must be composed of up to 3 printable ASCII
// glyphs (32-126)
Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
// move - the bearing for the rover to turn to // move - the bearing for the rover to turn to
Bearing Bearing `protobuf:"varint,3,opt,name=bearing,proto3,enum=roveapi.Bearing" json:"bearing,omitempty"` Bearing Bearing `protobuf:"varint,4,opt,name=bearing,proto3,enum=roveapi.Bearing" json:"bearing,omitempty"`
// wait - the number of server ticks to wait
Number int32 `protobuf:"varint,4,opt,name=number,proto3" json:"number,omitempty"`
} }
func (x *Command) Reset() { func (x *Command) Reset() {
@ -687,6 +689,13 @@ func (x *Command) GetCommand() CommandType {
return CommandType_none return CommandType_none
} }
func (x *Command) GetNumber() int32 {
if x != nil {
return x.Number
}
return 0
}
func (x *Command) GetData() []byte { func (x *Command) GetData() []byte {
if x != nil { if x != nil {
return x.Data return x.Data
@ -701,13 +710,6 @@ func (x *Command) GetBearing() Bearing {
return Bearing_BearingUnknown return Bearing_BearingUnknown
} }
func (x *Command) GetNumber() int32 {
if x != nil {
return x.Number
}
return 0
}
// CommandRequest describes a set of commands to be requested for the rover // CommandRequest describes a set of commands to be requested for the rover
type CommandRequest struct { type CommandRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
@ -1425,12 +1427,12 @@ var file_roveapi_roveapi_proto_rawDesc = []byte{
0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x2e, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x2e, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x61, 0x70, 0x69, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x61, 0x70, 0x69,
0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x54, 0x79, 0x70, 0x65, 0x52, 0x07, 0x63, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x54, 0x79, 0x70, 0x65, 0x52, 0x07, 0x63, 0x6f,
0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18,
0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x2a, 0x0a, 0x07, 0x62, 0x65, 0x61, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x12, 0x0a,
0x72, 0x69, 0x6e, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x72, 0x6f, 0x76, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74,
0x65, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x65, 0x61, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x07, 0x62, 0x65, 0x61, 0x12, 0x2a, 0x0a, 0x07, 0x62, 0x65, 0x61, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x04, 0x20, 0x01,
0x61, 0x72, 0x69, 0x6e, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x65, 0x61,
0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x6a, 0x0a, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x07, 0x62, 0x65, 0x61, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x6a, 0x0a,
0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x2a, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x2a, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x10, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x61, 0x70, 0x69, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x32, 0x10, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x61, 0x70, 0x69, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75,

View file

@ -103,7 +103,7 @@ enum CommandType {
salvage = 6; salvage = 6;
// Transfers remote control into dormant rover // Transfers remote control into dormant rover
transfer = 7; transfer = 7;
// Waits for the specified number of server ticks (requires number) // Waits before performing the next command
wait = 8; wait = 8;
} }
@ -126,15 +126,15 @@ message Command {
// The command type // The command type
CommandType command = 1; CommandType command = 1;
// The number of times to execute the command (assumes 1 if not present or 0)
int32 number = 2;
// broadcast - a simple message, must be composed of up to 3 printable ASCII // broadcast - a simple message, must be composed of up to 3 printable ASCII
// glyphs (32-126) // glyphs (32-126)
bytes data = 2; bytes data = 3;
// move - the bearing for the rover to turn to // move - the bearing for the rover to turn to
Bearing bearing = 3; Bearing bearing = 4;
// wait - the number of server ticks to wait
int32 number = 4;
} }
// CommandRequest describes a set of commands to be requested for the rover // CommandRequest describes a set of commands to be requested for the rover