Thx for the comment, Logic! I'll do the redefinition "virtual map" into
"intermediate map", first of all because this sounds easier to understand!
Episode 2 - specific BD engine rules for each BD element
In this episode, I'm going to finish the explanation of the BD engine rules, so
after this episode, we'll know exactly how the BD engine works and can move
on to exploiting some specific rules for CSO effects!
In the previous episode, we've already seen that the BD engine is based on
cavescans. Each frame, each element in the current map is scanned one by
one. So what exactly does the BD engine do if it has a specific BD element in
the scanner?
First of all, remember that there are some
passive elements which
can't do anything on their own. These elements, which are dirt, empty space,
wall, magic wall, titanium wall, voodoo and outbox, are just skipped by the
scanner. (Of course, these elements still make a huge difference when
detected!)
Before I start analyzing all active elements, I have one more note about
"states" that the BD engine has to remember for more than just one frame. These states are:
Kill Rockford (on/off): (switched "on" if a voodoo gets killed by a fly)
Amoeba state (dormant/awake/trapped/overgrown):
A dormant amoeba is one that is trapped from the beginning (silent).
An awake amoeba is the "normal" one: makes noise, grows unpredictably...
A trapped amoeba is ready to convert into diamonds.
An overgrown amoeba (usually >200 pieces) is ready to convert into boulder.
Amoeba growth speed (slow/fast): changes from "slow" to "fast" when
the amoeba timer runs out.
Magic wall state (dormant/active/dead): starts with "dormant",
changes into "active" as soon as there's something to convert, then changes
into "dead" after the magic wall timer runs out.
Outbox state (open/close): changes from "close" to "open" when
Rockford has collected enough diamonds.
And, last but not least, the visible ones: cave timer, collected diamonds,
score.
At the start of a cave (i.e. in the initial map), the states are always as follos:
Kill Rockford: off
Amoeba state: dormant
Amoeba growth speed: slow
Magic wall: dormant
Outbox: close
Now let's start! What does the engine do if each active BD element is in the
cavescanner?
General note 1: Whenever a BD element movesor grows, it gets a
"delay state" mark. Elements with delay state are always passive, i.e. skipped
by the scanner.. At the end of each frame, all delay states are removed.
General note 2: If an element explodes, the BD engine detects all eight
surrounding elements and converts them into explosion smoke (phase 1) or,
in case of a butterfly, diamond birth (phase 1).Exception: Titanium walls
aren't converted. All explosion smoke/diamond birth pieces get delay states.
General note 3: I won't mention any sound effects or animations - we
all know them, and they aren't interesting for our topic!
Rockford
1. If the "kill Rockford" state is on, then Rockford explodes.
2. Otherwise, the engine asks the player for his input:
2a) If the player's input is "move up/down", the BD engine detects the element in this direction.
If it's dirt or empty space, Rockford moves there.
If it's a diamond, Rockford moves into the diamond and the diamond
counter is increased. If now the diamond counter is equal to the diamond
requirement, the outbox state is changed from "close" into "open".
If it's an open outbox, the cave is successfully finished.
In any other case, Rockford stays where he is.
2b) If the player's input is "move left/right", the same happens as 2a), with
the following extra possibility:
If the detected element is a boulder, the engine also detects the element
behind the boulder. Now, in case of empty space, Rockford gets a 25% chance
to push the boulder and in case of success, Rockford and the boulder are both
moved.
2c) If the player's input is "snap", the same things happen as in 2a) or 2b),
the only difference being that in case of a successful snap, the engine does
not move Rockford but changes the snapped element into empty space.
Note: Rockford does not explode when he touches a fly! It's always the
fly's job to do the explosion. That's the reason why Rockford can touch a fly
from top or left: in these two cases, Rockford is scanned before the fly and
escapes before the fly detects him and explodes. This specific rule defines a
whole category of CSO effects which I'll later call "explosion checks"!
Boulder
The element "boulder" is in fact split in two - "(dormant) boulder" and "falling
boulder". They look identical for the player, but they do make a difference for
the BD engine!
(Dormant) boulder
The engine detects the element below the boulder:
(A)
If it's empty space, then the boulder moves down and converts into
a "falling boulder".
(B)
If it's another (dormant) boulder, a (dormant) diamond or a wall, the
engine detects the two elements to the left and to the bottom-left side of the
scanned boulder.
(B1)
If both are empty space, the boulder is moved left and converts
into a "falling boulder". (the boulder "falls sideways")
(B2)
Otherwise, the engine detects the two elements to the right and
bottom-right side of the scanned boulder:
(B21)
If both are empty space, the boulder moves right and converts
into a "falling boulder".
(B22)
Otherwise, the boulder does nothing.
(C)
In any other case, the boulder does nothing.
Falling boulder
The engine detects the element below the falling boulder:
(A)
If it's empty space, then the falling boulder moves down.
(B)
If it's Rockford, a firefly or a butterfly, the detected element explodes.
(C)
If it's a (dormant) boulder, a (dormant) diamond or a wall, the
engine detects the two elements to the left and to the bottom-left side of the
scanned falling boulder.
(C1)
If both are empty space, the falling boulder is moved left.
(C2)
Otherwise, the engine detects the two elements to the right and
bottom-right side of the scanned falling boulder:
(C21)
If both are empty space, the falling boulder moves right
(C22)
Otherwise, the falling boulder does not move, but it converts into
a (dormant) boulder.
(D)
If there's a dormant or active magic wall, the engine detects the
element below that magic wall:
(D1) In case of empty space, this space is filled with a falling diamond. The
falling boulder in the scanner vanishes and, if the magic wall was dormant,
the state changes into "active". The magic wall timer starts.
(D2) In any other case, the falling boulder in the scanner vanishes and, if the
magic wall was dormant, it changes into "active".
(E) If there's a dead magic wall, the falling boulder vanishes.
(F)
In any other case, the falling boulder converts into a (dormant)
boulder.
Note: That's how the magic wall can be a passive element - the falling
boulder does all the conversion work by itself, so the magic wall doesn't do
anything on its own!
Note2: When a falling boulder falls through a magic wall, it moves two
steps at a time, i.e. it falls double as quickly as usual!
Diamond/ Falling Diamond
That's quickly explained - diamonds just behave 1:1 analogously to boulders!
In fact, the only difference between diamonds and boulders occurs when
they're detected by Rockford.(OK, and also when an amoeba decides how to
convert.)
Firefly (facing left)
Fireflies, too, aren't just one element for the BD engine - in fact, the element
"firefly" is split into four, one for each facing direction. I'll explain what a
"firefly (left)" does, the others are just analogous:
1. First, the firefly makes an "explosion check". The BD engine detects the
four elements touching the firefly, and if it finds Rockford, an amoeba or a
voodoo, the firefly explodes. In case of a voodoo, the engine also activates
the "kill Rockford" checkmark after the end of the frame.
2. If the explosion check was negative, the engine detects the element below
the firefly (or, from the firefly's point of view, to its left side.)
(2A) If there's empty space, the firefly moves there and changes into a "firefly
(down)".
(2B) Otherwise, the engine detects the element to the firefly's left (from the
fly's point of view: forward).
(2B1) If there's empty space, the firefly moves there.
(2B2) If not, the firefly doesn't move but changes into a "firefly (up)". (From
the fly's point of view, it turns right).
Butterfly
Butterflies just behave the same way as fireflies, with two exceptions:
1. Butterflies explode into diamond birth instead of explosion smoke.
2. The directions in which the butterfly turns and moves (from the fly's point
of view) are reversed, compared with a firefly.
Amoeba
With an amoeba in the scanner, the BD engine's actions depend on the
current amoeba state (dormant, awake, trapped, overgrown):
(A) Dormant amoeba
The BD engine detects the four elements touching the amoeba.
(A1) If at least one of them is dirt or empty space, the amoeba state is
changed into "awake". The engine generates a random number to decide
whether the amoeba wants to grow and, if so, into which direction. If, for
example, the random number says "grow left", the BD engine again detects
the element to the amoeba's left side. If this is dirt or empty space, the
amoeba grows into it. Otherwise, or if the random number says "do not
grow", nothing happens.
(A2) If none of the four elements is dirt or empty space, nothing happens at
all.
(B) Awake amoeba
In this state, the BD engine has three things to consider each frame:
1. an amoeba piece counter
2. a "stay awake" checkmark
3. an "overgrown" checkmark
Now if an amoeba is scanned while the amoeba state is "awake", the BD
engine increases the amoeba piece counter and, if it hits 200, the amoeba
state is changed into "overgrown". Next, the engine detects the four elements
touching the amoeba.
(A) If none of them is dirt or empty space, nothing happens (the scanner
moves on).
(B) If at least one of them is dirt or empty space, the engine activates the
"stay awake" checkmark (if it wasn't activated before). Then, a random numer
decides whether the amoeba wants to grow and in which direction. If, for
example, the result is "grow down", the engine detects the element below the
amoeba. In case of dirt or empty space, the amoeba grows there and the
amoeba counter is increased, otherwise nothing happens.
If, at the end of the cavescan, the "stay awake" checkmark was not activated,
the amoeba state is changed into "trapped".
Trapped amoeba
The amoeba is changed into a diamond.
Overgrown amoeba
The amoeba is changed into a boulder.
Note:We see that if an amoeba is trapped, it is changed into diamonds
piece by piece in the following frame. This makes it actually possible for a
firefly to trap an amoeba without exploding! We'll see exactly how it works
when it comes to analyzing the CSO effects!
Note 2: An interesting question is what happens with an amoeba that
is trapped into exactly 200 pieces. Is it trapped or overgrown? According to
my above "programming" it would be trapped and give you 200 diamonds, but
there are also modern BD engines which give such an amoeba the
"overgrown" state.In this case, the max amount of diamonds that you can get
from an amoeba would be 199. That's just a side note, as there's no relevance
for our topic here.
Slime
First, a random number is generated. Based on the slime permeability of the
cave, the random number decides whether the current piece of slime shall be
active in this frame.
(A) If the slime is not active, nothing happens.
(B) If the slime is active, the BD engine detects whether there's a (dormant)
boulder/diamond above the slime and, at the same time, empty space below
the slime.
(B1) If not both is the case, nothing happens.
(B2) If both is the case, the boulder/diamond vanishes while at the same time
the empty space below the slime is changed into a falling boulder/diamond.
Growing wall
If the BD engine scans a horizontally growing wall, it detects the elements to
the wall's left and right side. If there's empty space, the wall grows into it. It
can also simultaneousely grow into both directions. Analogous for
vertically/bidirectional gwalls.
Explosion smoke
This exists in four phases. Phase 1-3 change into the next phase when
scanned, phase 4 changes into empty space. Analogous for diamond birth.
Whoa, that was a lot of theory! But, as I mentioned, it was necessary to write
all this down as I want to be able to refer to this later on. I'm almost sure that
I haven't given everything 100% correctly, but I'm happy as long as there are
no "visible" mistakes, i.e. mistakes that can actually lead to false engine
behaviour in a cave. If I have made such a mistake, I would be happy to be
corrected! Every detail is a potential new CSO effect!
In the next episode, we'll finally start to systematically analyze and categorize
CSO effects, with the goal to discover every possible effect that can be made
with the classical elements!