Skip to content

Commit 7b9d842

Browse files
authored
add goal field to scenarios (#450)
If there is a goal, immediately pop up a dialog with the goal, then allow showing it any time afterwards with ^G. See #356.
1 parent 23817a5 commit 7b9d842

File tree

12 files changed

+305
-222
lines changed

12 files changed

+305
-222
lines changed

data/scenarios/03Challenges/00-test.yaml

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
name: Test challenge
22
description: A very difficult challenge that will test the utmost limits of your ability to 'move' and 'grab'. This is actually a placeholder challenge and will be replaced with more suitable challenges soon.
3-
entities:
4-
- name: goal
5-
display:
6-
attr: device
7-
char: 'X'
8-
description:
9-
- Use your grabber to harvest a lambda.
10-
properties: [portable]
3+
goal:
4+
- Use your grabber to harvest a lambda.
115
win: |
126
try {
137
as base {has "lambda"}
@@ -23,7 +17,6 @@ robots:
2317
- logger
2418
- grabber
2519
inventory:
26-
- [1, goal]
2720
- [0, lambda]
2821
world:
2922
default: [blank, none]

data/scenarios/03Challenges/01-chess_horse.yaml

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
name: Chess Knight
22
description: In this quirky challenge, you move as the chess knight piece. Can you capture the enemy king?
3+
goal:
4+
- Robots can use the 'move' command to move.
5+
But they only 'turn' in cardinal directions.
6+
- You are special. You are a knight.
7+
- Go forth and capture the King!
38
entities:
4-
- name: goal
5-
display:
6-
attr: device
7-
char: 'X'
8-
description:
9-
- |
10-
Robots can use the 'move' command to move.
11-
But they only 'turn' in cardinal directions.
12-
13-
You are special. You are a knight.
14-
15-
Go forth and capture the King!
16-
properties: [portable]
179
- name: knownwater
1810
display:
1911
attr: water
@@ -38,8 +30,7 @@ robots:
3830
devices:
3931
- treads
4032
- logger
41-
inventory:
42-
- [1, goal]
33+
inventory: []
4334
display:
4435
char: ''
4536
- name: king

data/scenarios/03Challenges/02-drill_test.yaml

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Test drill
22
description: This is a developer playground and will be replaced with more suitable challenges soon.
3+
goal:
4+
- Send robots to mine rock, iron and copper.
35
win: |
46
try {
57
i <- as base {has "iron ore"};
@@ -20,7 +22,6 @@ robots:
2022
- plasma cutter
2123
- 3D printer
2224
inventory:
23-
- [1, goal]
2425
- [2, metal drill]
2526
- [1, drill]
2627
- [3, logger]
@@ -49,15 +50,7 @@ world:
4950
│..AAA│ ~~
5051
│....C│ ~
5152
└─────┘ ~
52-
entities:
53-
- name: goal
54-
display:
55-
attr: device
56-
char: 'X'
57-
description:
58-
- Send robots to mine rock, iron and copper.
59-
properties: [portable]
60-
53+
entities:
6154
## KNOWN ENTITIES
6255
- name: knownwater
6356
display:

data/scenarios/03Challenges/03-teleport.yaml

+43-50
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,10 @@
11
name: Portal room
22
description: An impossible challenge - can you magically jump across the water?
3-
entities:
4-
- name: goal
5-
display:
6-
attr: device
7-
char: 'X'
8-
description:
9-
- Get to the other room and grab the lambda.
10-
- Oh wait.
11-
- The tunnel is flooded.
12-
- Just give up then. It is impossible to get there.
13-
properties: [portable]
14-
## KNOWN ENTITIES
15-
- name: knownwater
16-
display:
17-
attr: water
18-
char: ' '
19-
description:
20-
- An infinite ocean of water.
21-
properties: [known, portable, growable, liquid]
22-
growth: [0,0]
23-
yields: water
24-
- name: knownwavywater
25-
display:
26-
attr: water
27-
char: '~'
28-
description:
29-
- An infinite ocean of water.
30-
properties: [known, portable, growable, liquid]
31-
growth: [0,0]
32-
yields: water
33-
- name: knowntree
34-
display:
35-
attr: plant
36-
char: 'T'
37-
description:
38-
- A tree.
39-
properties: [portable, growable, known]
40-
yields: tree
41-
growth: [500, 600]
42-
- name: knownflower
43-
display:
44-
attr: flower
45-
char: '*'
46-
description:
47-
- A flower.
48-
yields: flower
49-
properties: [known]
50-
3+
goal:
4+
- Get to the other room and grab the lambda.
5+
- Oh wait.
6+
- The tunnel is flooded.
7+
- Just give up then. It is impossible to get there.
518
win: |
529
try {
5310
as base {has "lambda"}
@@ -63,7 +20,6 @@ robots:
6320
- logger
6421
- grabber
6522
inventory:
66-
- [1, goal]
6723
- [0, lambda]
6824
- name: portkey1
6925
system: true
@@ -121,4 +77,41 @@ world:
12177
│_....._ _..λ.._│
12278
└┐.....┌───┐*...T┌┘ ~
12379
~└─────┘ ~~└─────┘~
124-
~~~ ~ ~ ~
80+
~~~ ~ ~ ~
81+
entities:
82+
## KNOWN ENTITIES
83+
- name: knownwater
84+
display:
85+
attr: water
86+
char: ' '
87+
description:
88+
- An infinite ocean of water.
89+
properties: [known, portable, growable, liquid]
90+
growth: [0,0]
91+
yields: water
92+
- name: knownwavywater
93+
display:
94+
attr: water
95+
char: '~'
96+
description:
97+
- An infinite ocean of water.
98+
properties: [known, portable, growable, liquid]
99+
growth: [0,0]
100+
yields: water
101+
- name: knowntree
102+
display:
103+
attr: plant
104+
char: 'T'
105+
description:
106+
- A tree.
107+
properties: [portable, growable, known]
108+
yields: tree
109+
growth: [500, 600]
110+
- name: knownflower
111+
display:
112+
attr: flower
113+
char: '*'
114+
description:
115+
- A flower.
116+
yields: flower
117+
properties: [known]

src/Swarm/Game/Entity.hs

+1-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ import Swarm.Util.Yaml
115115
import Swarm.Game.Display
116116
import Swarm.Language.Capability
117117
import Swarm.Language.Syntax (toDirection)
118-
import Swarm.Util (plural, (?))
118+
import Swarm.Util (plural, reflow, (?))
119119

120120
import Paths_swarm
121121

@@ -339,8 +339,6 @@ instance FromJSON Entity where
339339
<*> v .:? "capabilities" .!= []
340340
<*> pure empty
341341
)
342-
where
343-
reflow = T.unwords . T.words
344342

345343
-- | If we have access to an 'EntityMap', we can parse the name of an
346344
-- 'Entity' as a string and look it up in the map.

src/Swarm/Game/Scenario.hs

+10-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module Swarm.Game.Scenario (
2727
-- ** Fields
2828
scenarioName,
2929
scenarioDescription,
30+
scenarioGoal,
3031
scenarioCreative,
3132
scenarioSeed,
3233
scenarioEntities,
@@ -78,13 +79,15 @@ import Swarm.Game.Terrain
7879
import Swarm.Game.World
7980
import Swarm.Game.WorldGen (Seed, findGoodOrigin, testWorld2FromArray)
8081
import Swarm.Language.Pipeline (ProcessedTerm)
82+
import Swarm.Util (reflow)
8183
import Swarm.Util.Yaml
8284

8385
-- | A 'Scenario' contains all the information to describe a
8486
-- scenario.
8587
data Scenario = Scenario
8688
{ _scenarioName :: Text
8789
, _scenarioDescription :: Text
90+
, _scenarioGoal :: Maybe [Text]
8891
, _scenarioCreative :: Bool -- Maybe generalize this to a mode enumeration
8992
, _scenarioSeed :: Maybe Int
9093
, _scenarioEntities :: EntityMap
@@ -103,6 +106,7 @@ instance FromJSONE EntityMap Scenario where
103106
Scenario
104107
<$> liftE (v .: "name")
105108
<*> liftE (v .:? "description" .!= "")
109+
<*> liftE ((fmap . fmap . map) reflow (v .:? "goal"))
106110
<*> liftE (v .:? "creative" .!= False)
107111
<*> liftE (v .:? "seed")
108112
<*> pure em
@@ -115,9 +119,14 @@ instance FromJSONE EntityMap Scenario where
115119
-- | The name of the scenario.
116120
scenarioName :: Lens' Scenario Text
117121

118-
-- | A description of the scenario.
122+
-- | A high-level description of the scenario, shown /e.g./ in the
123+
-- menu.
119124
scenarioDescription :: Lens' Scenario Text
120125

126+
-- | An explanation of the goal of the scenario (if any), shown to the
127+
-- player during play.
128+
scenarioGoal :: Lens' Scenario (Maybe [Text])
129+
121130
-- | Whether the scenario should start in creative mode.
122131
scenarioCreative :: Lens' Scenario Bool
123132

0 commit comments

Comments
 (0)