Skip to content

Commit

Permalink
Add subworlds
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Jul 12, 2023
1 parent fb627fc commit a7a9099
Show file tree
Hide file tree
Showing 32 changed files with 980 additions and 274 deletions.
1 change: 1 addition & 0 deletions data/scenarios/Testing/00-ORDER.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@
1295-density-command.yaml
1138-structures
1356-portals
144-subworlds
2 changes: 2 additions & 0 deletions data/scenarios/Testing/144-subworlds/00-ORDER.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
basic-subworld.yaml
subworld-shared-structures.yaml
107 changes: 107 additions & 0 deletions data/scenarios/Testing/144-subworlds/basic-subworld.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
version: 1
name: Subworlds demo
description: |
Surface and underground with portals.
objectives:
- goal:
- |
`place` the "flower" on the white cell.
condition: |
j <- robotnamed "judge";
as j {ishere "flower"}
solution: |
run "scenarios/Testing/144-subworlds/_basic-subworld/solution.sw"
attrs:
- name: portal_in
fg: "#ff9a00"
bg: "#ff5d00"
- name: portal_out
fg: "#00a2ff"
bg: "#0065ff"
entities:
- name: telepad entrance
display:
attr: portal_in
char: "o"
description:
- Portal entrance
properties: [known]
- name: telepad exit
display:
attr: portal_out
char: "o"
description:
- Portal exit
properties: [known]
robots:
- name: base
dir: [1, 0]
devices:
- ADT calculator
- branch predictor
- comparator
- compass
- dictionary
- GPS receiver
- grabber
- lambda
- lodestone
- logger
- strange loop
- treads
- name: judge
dir: [1, 0]
system: true
display:
char: 'J'
invisible: true
known: [flower, boulder]
subworlds:
- name: underground
default: [blank]
palette:
'.': [dirt]
'f': [dirt, flower]
'b': [dirt, boulder]
'p':
cell: [dirt, telepad exit]
waypoint:
name: portal_out2
'P':
cell: [dirt, telepad entrance]
waypoint:
name: portal_in2
portals:
- entrance: portal_in2
exitInfo:
exit: portal_out1
subworldName: root
upperleft: [-1, 1]
map: |
b..b..b..b
.p..f...P.
b..b..b..b
world:
default: [blank]
palette:
'.': [grass]
'B': [grass, null, base]
't': [ice, null, judge]
'p':
cell: [grass, telepad exit]
waypoint:
name: portal_out1
'P':
cell: [grass, telepad entrance]
waypoint:
name: portal_in1
upperleft: [-1, 1]
portals:
- entrance: portal_in1
exitInfo:
exit: portal_out2
subworldName: underground
map: |
..........
.p.Bt...P.
..........
192 changes: 192 additions & 0 deletions data/scenarios/Testing/144-subworlds/subworld-shared-structures.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
version: 1
name: Subworld shared structures
description: |
Traverse floors of the tower
attrs:
- name: portal_in
fg: "#ff9a00"
bg: "#ff5d00"
- name: portal_out
fg: "#00a2ff"
bg: "#0065ff"
entities:
- name: telepad entrance
display:
attr: portal_in
char: "o"
description:
- Portal entrance
properties: [known]
- name: telepad exit
display:
attr: portal_out
char: "o"
description:
- Portal exit
properties: [known]
robots:
- name: base
dir: [1, 0]
loc: [0, 0]
devices:
- ADT calculator
- branch predictor
- comparator
- compass
- dictionary
- GPS receiver
- grabber
- lambda
- lodestone
- logger
- strange loop
- treads
known: [flower]
structures:
- name: minibox
structure:
palette:
'.': [stone]
'd': [dirt]
'f': [stone, flower]
'p':
cell: [grass, telepad exit]
waypoint:
name: portal_out
'P':
cell: [grass, telepad entrance]
waypoint:
name: portal_in
map: |
p....
.ddd.
.d.d.
.ddd.
....P
- name: flowers
structure:
mask: '.'
palette:
'f': [stone, flower]
map: |
f.f
.f.
f.f
subworlds:
- name: floor1
default: [blank]
palette:
'.': [dirt]
'f': [dirt, flower]
'p':
cell: [dirt, telepad exit]
waypoint:
name: portal_out
'P':
cell: [dirt, telepad entrance]
waypoint:
name: portal_in
placements:
- src: flowers
offset: [1, 1]
- src: minibox
offset: [0, 0]
orient:
up: west
portals:
- entrance: portal_in
exitInfo:
exit: portal_out
subworldName: floor2
upperleft: [0, 0]
map: |
.....
.....
.....
.....
.....
- name: floor2
default: [blank]
palette:
'.': [dirt]
'f': [dirt, flower]
'p':
cell: [dirt, telepad exit]
waypoint:
name: portal_out
'P':
cell: [dirt, telepad entrance]
waypoint:
name: portal_in
placements:
- src: flowers
offset: [1, 0]
- src: minibox
offset: [0, 0]
orient:
up: south
portals:
- entrance: portal_in
exitInfo:
exit: portal_out
subworldName: floor3
upperleft: [0, 0]
map: |
.....
.....
.....
.....
.....
- name: floor3
default: [blank]
palette:
'.': [dirt]
'f': [dirt, flower]
'p':
cell: [dirt, telepad exit]
waypoint:
name: portal_out
'P':
cell: [dirt, telepad entrance]
waypoint:
name: portal_in
placements:
- src: flowers
offset: [1, -2]
- src: minibox
offset: [0, 0]
orient:
up: east
portals:
- entrance: portal_in
exitInfo:
exit: portal_out
subworldName: root
upperleft: [0, 0]
map: |
.....
.....
.....
.....
.....
world:
default: [blank]
palette:
'.': [grass]
upperleft: [0, 0]
placements:
- src: flowers
offset: [0, -2]
- src: minibox
offset: [0, 0]
portals:
- entrance: portal_in
exitInfo:
exit: portal_out
subworldName: floor1
map: |
.....
.....
.....
.....
.....
9 changes: 6 additions & 3 deletions src/Swarm/Doc/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import Swarm.Game.Failure qualified as F
import Swarm.Game.Failure.Render qualified as F
import Swarm.Game.Recipe (Recipe, loadRecipes, recipeInputs, recipeOutputs, recipeRequirements, recipeTime, recipeWeight)
import Swarm.Game.ResourceLoading (getDataFileNameSafe)
import Swarm.Game.Robot (equippedDevices, instantiateRobot, robotInventory)
import Swarm.Game.Robot (Robot, equippedDevices, instantiateRobot, robotInventory)
import Swarm.Game.Scenario (Scenario, loadScenario, scenarioRobots)
import Swarm.Game.WorldGen (testWorld2Entites)
import Swarm.Language.Capability (Capability)
Expand Down Expand Up @@ -551,11 +551,14 @@ classicScenario = do
entities <- loadEntities >>= guardRight "load entities"
fst <$> loadScenario "data/scenarios/classic.yaml" entities

startingHelper :: Scenario -> Robot
startingHelper = instantiateRobot 0 . head . view scenarioRobots

startingDevices :: Scenario -> Set Entity
startingDevices = Set.fromList . map snd . E.elems . view equippedDevices . instantiateRobot 0 . head . view scenarioRobots
startingDevices = Set.fromList . map snd . E.elems . view equippedDevices . startingHelper

startingInventory :: Scenario -> Map Entity Int
startingInventory = Map.fromList . map swap . E.elems . view robotInventory . instantiateRobot 0 . head . view scenarioRobots
startingInventory = Map.fromList . map swap . E.elems . view robotInventory . startingHelper

-- | Ignore utility entities that are just used for tutorials and challenges.
ignoredEntities :: Set Text
Expand Down
6 changes: 5 additions & 1 deletion src/Swarm/Game/Log.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Data.Text (Text)
import GHC.Generics (Generic)
import Swarm.Game.CESK (TickNumber)
import Swarm.Game.Location (Location)
import Swarm.Game.Universe (Cosmo)

-- | Severity of the error - critical errors are bugs
-- and should be reported as Issues.
Expand Down Expand Up @@ -61,8 +62,11 @@ data LogEntry = LogEntry
-- ^ The name of the robot that generated the entry.
, _leRobotID :: Int
-- ^ The ID of the robot that generated the entry.
, _leLocation :: Location
, _leLocation :: Maybe (Cosmo Location)
-- ^ Location of the robot at log entry creation.
-- "Nothing" represents omnipresence for the purpose of proximity.
-- TODO: Define a type isomorphic to Maybe that makes this explict.
-- C.f. "cosmoMeasure" which will have its own type that means the opposite.
, _leText :: Text
-- ^ The text of the log entry.
}
Expand Down
Loading

0 comments on commit a7a9099

Please sign in to comment.