Skip to content

Commit

Permalink
combustion
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Aug 20, 2023
1 parent 6f8716f commit b8fadf7
Show file tree
Hide file tree
Showing 14 changed files with 409 additions and 15 deletions.
39 changes: 34 additions & 5 deletions data/entities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@
A tall, living entity made of a tough cellular material called "wood".
They regrow after being harvested and are an important raw ingredient used
in making many different devices.
properties: [portable, growable, opaque]
properties: [portable, growable, opaque, combustible]
growth: [500, 600]
combustion:
ignition: 0.01
duration: [80, 120]
product: ash

- name: ash
display:
attr: rock
char: '#'
description:
- |
Burned-out remnants of combustion.
properties: [portable]

- name: branch
display:
Expand All @@ -25,15 +38,23 @@
char: 'l'
description:
- A wooden log, obtained by harvesting a tree and cutting off its branches.
properties: [portable]
properties: [portable, combustible]
combustion:
ignition: 0.05
duration: [40, 80]
product: ash

- name: board
display:
attr: wood
char: 'w'
description:
- A wooden board, made by cutting a log into pieces.
properties: [portable]
properties: [portable, combustible]
combustion:
ignition: 0.2
duration: [20, 40]
product: ash

- name: workbench
display:
Expand All @@ -57,7 +78,11 @@
description:
- A flat material made of pressed and dried wood fibers,
used as a surface on which to inscribe symbols.
properties: [portable]
properties: [portable, combustible]
combustion:
ignition: 0.5
duration: [10, 20]
product: ash

- name: PhD thesis
display:
Expand Down Expand Up @@ -336,8 +361,12 @@
- A plant with tufts of soft fibers that can be harvested and used
to make things, including sheets of material that the local
aliens like to drape over their bodies.
properties: [portable, growable]
properties: [portable, growable, combustible]
growth: [100, 800]
combustion:
ignition: 0.1
duration: [20, 40]
product: ash

- name: linotype
display:
Expand Down
133 changes: 133 additions & 0 deletions data/scenarios/Testing/1355-combustion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
version: 1
name: Combustion
creative: false
seed: 0
description: Demo of spreading fire
objectives:
- goal:
- Blow up the dynamite
condition: |
j <- robotnamed "judge";
as j {
ishere "crater";
};
solution: |
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;
move;
ignite forward;
turn right;
move;
ignite forward;
turn right;
move; move; move;
turn right;
move;
ignite left;
move;
turn right;
doN 2 (move; ignite left);
doN 14 move;
turn left;
doN 5 move;
turn left;
ignite right;
doN 8 move;
ignite right;
doN 10 move;
ignite right;
doN 8 move;
ignite right;
robots:
- name: base
dir: [1, 0]
devices:
- branch predictor
- calculator
- dictionary
- comparator
- logger
- treads
- torch
- name: judge
dir: [1, 0]
system: true
display:
invisible: true
char: J
entities:
- name: torch
display:
attr: wood
char: 't'
description:
- Can set things on fire
properties: [known, portable]
capabilities: [ignite]
- name: fuse
display:
attr: wood
char: '~'
description:
- Reliably combustible
combustion:
ignition: 1
duration: [8, 8]
product: null
properties: [known, portable, combustible]
- name: dynamite
display:
attr: red
char: '!'
description:
- Explosive material
combustion:
ignition: 1
duration: [2, 2]
product: crater
properties: [known, portable, combustible]
- name: crater
display:
attr: rock
char: '@'
description:
- Result of explosive excavation
properties: [known]
known: [ash, tree, log, board, paper, cotton]
world:
palette:
'Ω': [grass, null, base]
'T': [grass, tree]
'q': [grass, paper]
'l': [grass, log]
'b': [grass, board]
'i': [grass, cotton]
'F': [grass, fuse]
'd': [grass, dynamite, judge]
'.': [grass]
upperleft: [0, 0]
map: |
..iiii....bbbb..TT..llll....iiii.....
..iiii....bbbb..TT..llll....iiii.....
..iiii....bbbb..TT..llll....iiii.....
..iiii....bbbb..TT..llll....iiii.....
..iiii....bbbb..TT..llll....iiii.....
..iiii....bbbb..TT..llll....iiii.....
..TTTT....TTTT..TT..TTTT....TTTT.....
..TTTT....TTTT..TT..TTTT....TTTT.....
................TT...................
................TT...................
iiiiiiiiiii.....TT....FFFFF...FFFFF..
......iiiiii....TT....F...F...F...F..
iiiiiiiiiiiii...TT....F...F...F...F..
......iiiiiiii........F...F...F...F..
iiiiiiiiiiiiiii..Ω.FFFF...FFFFF...d..
......iiiiiiii.......................
iiiiiiiiiiiii.....qqqqqqqqqqqqqqqq...
......iiiiii......qqqqqqqqqqqqqqqq...
iiiiiiiiiii.......qqqqqqqqqqqqqqqq...
..................qqqqqqqqqqqqqqqq...
..................qqqqqqqqqqqqqqqq...
..................qqqqqqqqqqqqqqqq...
..................qqqqqqqqqqqqqqqq...
..................qqqqqqqqqqqqqqqq...
1 change: 1 addition & 0 deletions editors/emacs/swarm-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"turn"
"grab"
"harvest"
"ignite"
"place"
"give"
"equip"
Expand Down
2 changes: 1 addition & 1 deletion editors/vscode/syntaxes/swarm.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
{
"name": "keyword.other",
"match": "\\b(?i)(self|parent|base|if|inl|inr|case|fst|snd|force|undefined|fail|not|format|chars|split|charat|tochar|key|noop|wait|selfdestruct|move|backup|push|stride|turn|grab|harvest|place|give|equip|unequip|make|has|equipped|count|drill|use|build|salvage|reprogram|say|listen|log|view|appear|create|halt|time|scout|whereami|waypoint|detect|resonate|density|sniff|chirp|watch|surveil|heading|blocked|scan|upload|ishere|isempty|meet|meetall|whoami|setname|random|run|return|try|swap|atomic|instant|installkeyhandler|teleport|as|robotnamed|robotnumbered|knows)\\b"
"match": "\\b(?i)(self|parent|base|if|inl|inr|case|fst|snd|force|undefined|fail|not|format|chars|split|charat|tochar|key|noop|wait|selfdestruct|move|backup|push|stride|turn|grab|harvest|ignite|place|give|equip|unequip|make|has|equipped|count|drill|use|build|salvage|reprogram|say|listen|log|view|appear|create|halt|time|scout|whereami|waypoint|detect|resonate|density|sniff|chirp|watch|surveil|heading|blocked|scan|upload|ishere|isempty|meet|meetall|whoami|setname|random|run|return|try|swap|atomic|instant|installkeyhandler|teleport|as|robotnamed|robotnumbered|knows)\\b"
}
]
},
Expand Down
52 changes: 50 additions & 2 deletions src/Swarm/Game/Entity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
-- are mutually recursive (an inventory contains entities, which can
-- have inventories).
module Swarm.Game.Entity (
EntityName,

-- * Properties
EntityProperty (..),
GrowthTime (..),
defaultGrowthTime,
Combustibility (..),
defaultCombustibility,

-- * Entities
Entity,
Expand All @@ -31,6 +35,7 @@ module Swarm.Game.Entity (
entityDescription,
entityOrientation,
entityGrowth,
entityCombustion,
entityYields,
entityProperties,
hasProperty,
Expand Down Expand Up @@ -118,6 +123,8 @@ import Text.Read (readMaybe)
import Witch
import Prelude hiding (lookup)

type EntityName = Text

------------------------------------------------------------
-- Properties
------------------------------------------------------------
Expand All @@ -133,6 +140,8 @@ data EntityProperty
Opaque
| -- | Regrows from a seed after it is harvested.
Growable
| -- | Can use the Ignite command on it
Combustible
| -- | Regenerates infinitely when grabbed or harvested.
Infinite
| -- | Robots drown if they walk on this without a boat.
Expand Down Expand Up @@ -162,6 +171,24 @@ newtype GrowthTime = GrowthTime (Integer, Integer)
defaultGrowthTime :: GrowthTime
defaultGrowthTime = GrowthTime (100, 200)

-- | Properties of combustion
data Combustibility = Combustibility
{ ignition :: Double
-- ^ Rate of ignition by a neighbor, per tick.
-- When denoted as "lambda",
-- probability of ignition over a period "t" is:
-- 1 - e^(-(lambda * t))
-- See: https://math.stackexchange.com/a/1243629
, duration :: (Integer, Integer)
-- ^ min and max tick counts for combustion to persist
, product :: Maybe EntityName
-- ^ what entity, if any, is left over after combustion
}
deriving (Eq, Ord, Show, Read, Generic, Hashable, FromJSON, ToJSON)

defaultCombustibility :: Combustibility
defaultCombustibility = Combustibility 0.5 (100, 200) (Just "ash")

------------------------------------------------------------
-- Entity
------------------------------------------------------------
Expand Down Expand Up @@ -224,6 +251,8 @@ data Entity = Entity
-- a robot moves, it moves in the direction of its orientation.
, _entityGrowth :: Maybe GrowthTime
-- ^ If this entity grows, how long does it take?
, _entityCombustion :: Maybe Combustibility
-- ^ If this entity is combustible, how spreadable is it?
, _entityYields :: Maybe Text
-- ^ The name of a different entity obtained when this entity is
-- grabbed.
Expand All @@ -243,14 +272,15 @@ data Entity = Entity
-- | The @Hashable@ instance for @Entity@ ignores the cached hash
-- value and simply combines the other fields.
instance Hashable Entity where
hashWithSalt s (Entity _ disp nm pl descr orient grow yld props caps inv) =
hashWithSalt s (Entity _ disp nm pl descr orient grow combust yld props caps inv) =
s
`hashWithSalt` disp
`hashWithSalt` nm
`hashWithSalt` pl
`hashWithSalt` docToText descr
`hashWithSalt` orient
`hashWithSalt` grow
`hashWithSalt` combust
`hashWithSalt` yld
`hashWithSalt` props
`hashWithSalt` caps
Expand Down Expand Up @@ -284,7 +314,20 @@ mkEntity ::
[Capability] ->
Entity
mkEntity disp nm descr props caps =
rehashEntity $ Entity 0 disp nm Nothing descr Nothing Nothing Nothing (Set.fromList props) (Set.fromList caps) empty
rehashEntity $
Entity
0
disp
nm
Nothing
descr
Nothing
Nothing
Nothing
Nothing
(Set.fromList props)
(Set.fromList caps)
empty

------------------------------------------------------------
-- Entity map
Expand Down Expand Up @@ -345,6 +388,7 @@ instance FromJSON Entity where
<*> (v .: "description")
<*> v .:? "orientation"
<*> v .:? "growth"
<*> v .:? "combustion"
<*> v .:? "yields"
<*> v .:? "properties" .!= mempty
<*> v .:? "capabilities" .!= mempty
Expand Down Expand Up @@ -445,6 +489,10 @@ entityOrientation = hashedLens _entityOrientation (\e x -> e {_entityOrientation
entityGrowth :: Lens' Entity (Maybe GrowthTime)
entityGrowth = hashedLens _entityGrowth (\e x -> e {_entityGrowth = x})

-- | Susceptibility to and duration of combustion
entityCombustion :: Lens' Entity (Maybe Combustibility)
entityCombustion = hashedLens _entityCombustion (\e x -> e {_entityCombustion = x})

-- | The name of a different entity yielded when this entity is
-- grabbed, if any.
entityYields :: Lens' Entity (Maybe Text)
Expand Down
5 changes: 1 addition & 4 deletions src/Swarm/Game/Scenario/Topography/EntityFacade.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@
module Swarm.Game.Scenario.Topography.EntityFacade where

import Control.Lens ((^.))
import Data.Text (Text)
import Data.Yaml as Y (ToJSON (toJSON))
import Swarm.Game.Display (Display)
import Swarm.Game.Entity qualified as E

type EntityName = Text

-- | This datatype is a lightweight stand-in for the
-- full-fledged "Entity" type without the baggage of all
-- of its other fields.
-- It contains the bare minimum display information
-- for rendering.
data EntityFacade = EntityFacade EntityName Display
data EntityFacade = EntityFacade E.EntityName Display
deriving (Eq)

-- Note: This instance is used only for the purpose of WorldPalette
Expand Down
Loading

0 comments on commit b8fadf7

Please sign in to comment.