diff --git a/pkg/game/rover.go b/pkg/game/rover.go index a7e3fb3..693ba9a 100644 --- a/pkg/game/rover.go +++ b/pkg/game/rover.go @@ -1,10 +1,23 @@ package game import ( + "fmt" + "log" + "time" + "github.com/mdiluz/rove/pkg/objects" "github.com/mdiluz/rove/pkg/vector" ) +// RoverLogEntry describes a single log entry for the rover +type RoverLogEntry struct { + // Time is the timestamp of the entry + Time time.Time `json:"time"` + + // Text contains the information in this log entry + Text string `json:"text"` +} + // Rover describes a single rover in the world type Rover struct { // Unique name of this rover @@ -31,6 +44,21 @@ type Rover struct { // Charge is the amount of energy the rover has Charge int `json:"charge"` - // ChargeCharge is the maximum charge able to be stored + // MaximumCharge is the maximum charge able to be stored MaximumCharge int `json:"maximum-Charge"` + + // Logs Stores log of information + Logs []RoverLogEntry `json:"logs"` +} + +// AddLogEntryf adds an entry to the rovers log +func (r *Rover) AddLogEntryf(format string, args ...interface{}) { + text := fmt.Sprintf(format, args...) + log.Printf("%s log entry: %s", r.Name, text) + r.Logs = append(r.Logs, + RoverLogEntry{ + Time: time.Now(), + Text: text, + }, + ) } diff --git a/pkg/game/world.go b/pkg/game/world.go index a4a70af..b53dc7e 100644 --- a/pkg/game/world.go +++ b/pkg/game/world.go @@ -122,7 +122,8 @@ func (w *World) SpawnRover() (string, error) { } - log.Printf("Spawned rover at %+v\n", rover.Pos) + // Add a log entry for robot creation + rover.AddLogEntryf("created at %+v", rover.Pos) // Append the rover to the list w.Rovers[rover.Name] = rover @@ -160,6 +161,7 @@ func (w *World) RoverRecharge(rover string) (int, error) { // Add one charge if i.Charge < i.MaximumCharge { i.Charge++ + i.AddLogEntryf("recharged to %d", i.Charge) } w.Rovers[rover] = i @@ -239,6 +241,7 @@ func (w *World) WarpRover(rover string, pos vector.Vector) error { return fmt.Errorf("can't warp rover to occupied tile, check before warping") } + i.AddLogEntryf("warped to %+v", pos) i.Pos = pos w.Rovers[rover] = i return nil @@ -266,12 +269,15 @@ func (w *World) MoveRover(rover string, b bearing.Bearing) (vector.Vector, error // Get the tile and verify it's empty _, obj := w.Atlas.QueryPosition(newPos) if !obj.IsBlocking() { + i.AddLogEntryf("moved %s to %+v", b.String(), newPos) // Perform the move i.Pos = newPos w.Rovers[rover] = i } else { // If it is a blocking tile, reduce the rover integrity + i.AddLogEntryf("tried to move %s to %+v", b.String(), newPos) i.Integrity = i.Integrity - 1 + i.AddLogEntryf("had a collision, new integrity %d", i.Integrity) if i.Integrity == 0 { // TODO: The rover needs to be left dormant with the player } else { @@ -308,6 +314,7 @@ func (w *World) RoverStash(rover string) (objects.Type, error) { return objects.None, nil } + r.AddLogEntryf("stashed %c", obj.Type) r.Inventory = append(r.Inventory, obj) w.Rovers[rover] = r w.Atlas.SetObject(r.Pos, objects.Object{Type: objects.None}) @@ -480,6 +487,7 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) { if len(r.Inventory) > 0 && r.Integrity < r.MaximumIntegrity { r.Inventory = r.Inventory[:len(r.Inventory)-1] r.Integrity = r.Integrity + 1 + r.AddLogEntryf("repaired self to %d", r.Integrity) w.Rovers[rover] = r } case CommandRecharge: