862 |
void rotate_cluster(const Cluster &c); |
void rotate_cluster(const Cluster &c); |
863 |
void maybe_rotate_cluster(Direction dir); |
void maybe_rotate_cluster(Direction dir); |
864 |
|
|
|
void shuffle(int count); |
|
|
|
|
865 |
void message(const string& msg, const Value &val); |
void message(const string& msg, const Value &val); |
866 |
|
|
867 |
void on_creation(); |
void on_creation(); |
1052 |
// moving the cluster. |
// moving the cluster. |
1053 |
// |
// |
1054 |
// For partial clusters build bridges only on water and if |
// For partial clusters build bridges only on water and if |
1055 |
// the wielded item is not the magic wand. |
// the wielded item is NOT the magic wand. |
1056 |
|
|
1057 |
bool create_bridge = true; |
bool create_bridge = true; |
1058 |
|
|
1107 |
void |
void |
1108 |
PuzzleStone::rotate_cluster(const Cluster &c) |
PuzzleStone::rotate_cluster(const Cluster &c) |
1109 |
{ |
{ |
1110 |
if (c.size() > 1) { |
unsigned size = c.size(); |
1111 |
|
if (size > 1) { |
1112 |
vector<Stone*> stones; |
vector<Stone*> stones; |
1113 |
for (unsigned i=0; i<c.size(); ++i) |
for (unsigned i=0; i<size; ++i) |
1114 |
stones.push_back(YieldStone(c[i])); |
stones.push_back(YieldStone(c[i])); |
1115 |
|
|
1116 |
// exclude last list item |
// exclude last list item |
1117 |
for (unsigned i=0; i<c.size()-1; ++i) |
for (unsigned i=0; i<size-1; ++i) |
1118 |
SetStone(c[i+1], stones[i]); |
SetStone(c[i+1], stones[i]); |
1119 |
SetStone(c[0], stones.back()); |
SetStone(c[0], stones.back()); |
1120 |
} |
} |
1129 |
} |
} |
1130 |
|
|
1131 |
void |
void |
|
PuzzleStone::shuffle(int count) |
|
|
{ |
|
|
assert(oxyd1_compatible()); |
|
|
|
|
|
Direction move_dir = static_cast<Direction>(IntegerRand(0, 3)); |
|
|
Cluster c; |
|
|
find_row_or_column_cluster(c, get_pos(), reverse(move_dir), 1); |
|
|
if (!c.empty()) { |
|
|
GridPos last = c.back(); |
|
|
c.clear(); |
|
|
find_row_or_column_cluster(c, last, move_dir, 1); |
|
|
|
|
|
// if cluster too small to rotate -> turn direction by 90 deg |
|
|
if (c.size() <= 1) { |
|
|
move_dir = rotate(move_dir, true); |
|
|
c.clear(); |
|
|
find_row_or_column_cluster(c, last, move_dir, 1); |
|
|
} |
|
|
|
|
|
if (c.size() > 1) { |
|
|
|
|
|
// @@@ FIXME: check whether rotation is impossible |
|
|
// (e.g. blocked by unmoveable stone at both sides) |
|
|
|
|
|
while (count--) |
|
|
rotate_cluster(c); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
void |
|
1132 |
PuzzleStone::trigger_explosion(double delay) { |
PuzzleStone::trigger_explosion(double delay) { |
1133 |
if (state == IDLE) { |
if (state == IDLE) { |
1134 |
state = EXPLODING; |
state = EXPLODING; |
1178 |
|
|
1179 |
void |
void |
1180 |
PuzzleStone::message(const string& msg, const Value &val) { |
PuzzleStone::message(const string& msg, const Value &val) { |
1181 |
if (oxyd1_compatible()) { |
if (msg == "scramble") { |
1182 |
if (msg == "init") { |
// oxyd levels contain explicit information on how to |
1183 |
// shuffle oxyd1 style puzzle pieces at level startup. |
// scramble puzzle stones. According to that information |
1184 |
// only done this way if gametype is GAMET_ENIGMA. |
// a "scramble" message is send to specific puzzle stones |
1185 |
if (enigma::GameCompatibility == GAMET_ENIGMA) { |
// together with information about the direction. |
1186 |
int count = options::Difficulty == DIFFICULTY_EASY |
// |
1187 |
? 1 |
// enigma levels may create scramble messages using |
1188 |
: IntegerRand(0, 4); |
// AddScramble() and SetScrambleIntensity() |
1189 |
|
|
1190 |
|
Direction dir = static_cast<Direction>(val.get_double()); |
1191 |
|
Cluster c; |
1192 |
|
find_row_or_column_cluster(c, get_pos(), dir, oxyd1_compatible()); |
1193 |
|
|
1194 |
shuffle(count); |
int size = c.size(); |
1195 |
} |
|
1196 |
|
// warning("received 'scramble'. dir=%s size=%i", to_suffix(dir).c_str(), size); |
1197 |
|
|
1198 |
|
if (size >= 2) { |
1199 |
|
int count = IntegerRand(1, size-1); |
1200 |
|
while (count--) |
1201 |
|
rotate_cluster(c); |
1202 |
} |
} |
1203 |
else if (msg == "scramble") { |
else { |
1204 |
// oxyd levels contain explicit information on how to |
warning("useless scramble (cluster size=%i)", size); |
|
// shuffle puzzle stones. According to that information |
|
|
// a "scramble" message is send to specific puzzle stones |
|
|
// together with information about the direction. |
|
|
// only done this way if gametype is not GAMET_ENIGMA. |
|
|
|
|
|
Direction dir = static_cast<Direction>(val.get_double()); |
|
|
Cluster c; |
|
|
find_row_or_column_cluster(c, get_pos(), dir, 1); |
|
|
|
|
|
int size = c.size(); |
|
|
if (size >= 2) { |
|
|
int count = IntegerRand(1, size-1); |
|
|
while (count--) |
|
|
rotate_cluster(c); |
|
|
} |
|
1205 |
} |
} |
1206 |
} |
} |
1207 |
} |
} |