luv

Workshop wiki

commands.lisp

luvcraft/agent/commands.lisp

system luvcraft/agent · 25 definitions · on GitHub

in-package#:luvcraft.agent

The agent's first verbs, as CLIM commands in a table of their own.

Each one returns an object, and what the model reads is that object under the model view; what the HUD draws is the same object under the cassette view. The docstring is the tool description the provider sees, so it is written to the model.

define-command-tableluvcraft-agent
defgenericembodied-agent-name
agent
:documentation

The short speaker name shown for an embodied agent.

--------------------------------------------------------------------- Where am I

defclassbody-place
x:initarg:x:readerplace-x
y:initarg:y:readerplace-y
z:initarg:z:readerplace-z
subject:initarg:subject:readerplace-subject
yaw:initarg:yaw:initformnil:readerplace-yaw
pitch:initarg:pitch:initformnil:readerplace-pitch
looking-p:initarg:looking-p:initformnil:readerplace-looking-p
target:initarg:target:initformnil:readerplace-target:documentation"A BLOCK-REPORT for the block under the crosshair, or NIL."
:documentation

Where one command subject stands and, when applicable, looks.

defclassplayer-place
:documentation

Compatibility specialization for an explicitly player place.

defuncommand-subject
session

The embodied object whose command is running: agent presence, then player.

or
luvcraft:luvcraft-session-playersession
defuncommand-subject-name
subjectsession
if
eqsubject
luvcraft:luvcraft-session-playersession
"you"
defgenericcommand-subject-bearing
subjectsession
:documentation

Return subject's retained YAW and PITCH, or NIL values without a facing.

defmethodcommand-subject-bearing
subjectt
session

Use physical motion as the open fallback for bodies without authored facing.

if
eqsubject
luvcraft:luvcraft-session-playersession
let
camera
luvcraft:luvcraft-session-camerasession
let*
velocity
x
luvcraft::vec3-xvelocity
z
luvcraft::vec3-zvelocity
if
>
+
*xx
*zz
1d-4
values
atanxz
0d0
valuesnilnil
defuncompass-word
yaw

A rough compass word for yaw in radians, with +z as north.

let*
turns
/
modyaw
*2pi
*2pi
eighths
mod
round
*turns8
8
ntheighths'
"north""north-east""east""south-east""south""south-west""west""north-west"
define-presentation-methodpresent
objectstream
viewtextual-view
&key
formatstream"~:(~A~) stand~:[s~;~] at x=~D y=~D z=~D"
place-subjectobject
string=
place-subjectobject
"you"
place-xobject
place-yobject
place-zobject
when
place-yawobject
formatstream" facing ~A"
compass-word
place-yawobject
when
place-looking-pobject
if
place-targetobject
progn
write-string", looking at "stream
present
place-targetobject
'block-report:streamstream:viewview
write-string", looking at nothing in reach."stream
define-command
com-where-am-i:command-tableluvcraft-agent:name"Where Am I"
"Report your body's block position and, when you have one, facing and target."
let*
subject
player-p
eqsubject
luvcraft:luvcraft-session-playersession
multiple-value-bind
xyz
multiple-value-bind
yawpitch
make-instance'body-place:subject
command-subject-namesubjectsession
:xx:yy:zz:yawyaw:pitchpitch:looking-pplayer-p:target
andhit
let
c
luvcraft::block-ray-hit-coordinatehit
block-report-atsession
luvcraft::world-coordinate-xc
luvcraft::world-coordinate-yc
luvcraft::world-coordinate-zc

--------------------------------------------------------------------- Moving to a place

define-command
com-move-to:command-tableluvcraft-agent:name"Move To"
x'integer:prompt"x":documentation"nearby destination x cell"
y'integer:prompt"y":documentation"supported destination y cell"
z'integer:prompt"z":documentation"nearby destination z cell"
"Move your body to the nearby supported cell x y z. The call waits until you arrive or movement fails; basic wayfinding can step one block up or down and route around solid blocks."
let*
unlesssubject
error"No embodied command subject is present."
luvcraft:start-body-move-tosubject
luvcraft:luvcraft-session-worldsession
xyz
defmethodcommand-result-presentation-type
command
eql'com-move-to
value
declare
ignorevalue
'luvcraft:body-move-action
define-presentation-methodpresent
actionstream
viewtextual-view
&key
destructuring-bind
xyz
luvcraft:body-move-action-destinationaction
formatstream"Move To x=~D y=~D z=~D: ~(~A~) after ~,2Fs"xyz
luvcraft:body-move-action-statusaction
luvcraft:body-move-action-elapsedaction
when
luvcraft:body-move-action-detailaction
formatstream" (~A)"
luvcraft:body-move-action-detailaction

--------------------------------------------------------------------- Blocks

defclassblock-report
x:initarg:x:readerblock-report-x
y:initarg:y:readerblock-report-y
z:initarg:z:readerblock-report-z
kind:initarg:kind:readerblock-report-kind:documentation"A BLOCK-KIND, or NIL for air."
residency:initarg:residency:readerblock-report-residency
:documentation

One cell of the world as it was when asked.

defunblock-report-at
sessionxyz
multiple-value-bind
kindresidency
luvcraft:world-block-at
luvcraft:luvcraft-session-worldsession
xyz
make-instance'block-report:xx:yy:zz:kindkind:residencyresidency
define-presentation-methodpresent
objectstream
viewtextual-view
&key
formatstream"~A at x=~D y=~D z=~D~@[ (~(~A~))~]"
if
block-report-kindobject
present-to-string
block-report-kindobject
'luvcraft:block-kind:viewview
"air"
block-report-xobject
block-report-yobject
block-report-zobject
and
not
eq:resident
block-report-residencyobject
block-report-residencyobject
define-command
com-block-at:command-tableluvcraft-agent:name"Block At"
x'integer:prompt"x"
y'integer:prompt"y"
z'integer:prompt"z"
"Report which block kind is at integer cell x y z (air when empty)."
define-command
com-place-block-at:command-tableluvcraft-agent:name"Place Block At"
kind'luvcraft:block-kind:prompt"kind"
x'integer:prompt"x"
y'integer:prompt"y"
z'integer:prompt"z"
"Place a block of the given kind at integer cell x y z, replacing what is there."
let*
world
luvcraft:luvcraft-session-worldsession
multiple-value-bind
oldresidency
declare
ignoreold
unless
eqresidency:resident
error"Cell ~D ~D ~D is not loaded (~(~A~)); stay nearer the player."xyzresidency
when
luvcraft::luvcraft-session-physicssession
luvcraft::wake-physics-bodies-near
luvcraft::luvcraft-session-physicssession
+x0.5
+y0.5
+z0.5
2.5
block-report-atsessionxyz

--------------------------------------------------------------------- Handles and the evaluator

define-command
com-describe-handle:command-tableluvcraft-agent:name"Describe Handle"
thing'handle:prompt"handle"
"Read the whole of something an earlier result named by #ABCD handle."
if
stringpthing
thing
with-output-to-string
stream
describethingstream
defmethodcommand-output-line-limit
command
eql'com-describe-handle
400
defmethodcommand-tool-runs-on-canvas-p
command
eql'com-eval
nil
defmethodcommand-result-presentation-type
command
eql'com-eval
value
declare
ignorevalue
'expression
define-command
com-eval:command-tableluvcraft-agent:name"Eval"
form'string:prompt"form"
"Evaluate one Common Lisp form in the live image (package LUVCRAFT) and return its values. luvcraft:*session* is the game."
let
*package*
find-package'#:luvcraft
eval
read-from-stringform