354 |
|
|
355 |
|
|
356 |
SwapStone(Stone *exchanged_with, Direction dir) |
SwapStone(Stone *exchanged_with, Direction dir) |
357 |
: Stone("st-swap") |
: Stone(exchanged_with->get_kind()) // fake kind |
358 |
, state(GO) |
, state(GO) |
359 |
, in_exchange_with(exchanged_with) |
, in_exchange_with(exchanged_with) |
360 |
, move_dir(dir) |
, move_dir(dir) |
367 |
Stone::on_creation(); |
Stone::on_creation(); |
368 |
} |
} |
369 |
|
|
370 |
|
void on_removal() { |
371 |
|
if (state != IDLE) { |
372 |
|
g_timer.remove_alarm(this); |
373 |
|
} |
374 |
|
} |
375 |
|
|
376 |
void alarm() { |
void alarm() { |
377 |
switch (state) { |
switch (state) { |
378 |
case COME: |
case COME: |
384 |
assert(in_exchange_with); |
assert(in_exchange_with); |
385 |
Stone *st = in_exchange_with; |
Stone *st = in_exchange_with; |
386 |
GridPos p = get_pos(); |
GridPos p = get_pos(); |
387 |
|
state = IDLE; |
388 |
KillStone(p); |
KillStone(p); |
389 |
SetStone(p, st); |
SetStone(p, st); |
390 |
st->on_move(); |
st->on_move(); |
401 |
GridPos oldp = get_pos(); |
GridPos oldp = get_pos(); |
402 |
GridPos newp = move(oldp, impulse.dir); |
GridPos newp = move(oldp, impulse.dir); |
403 |
|
|
404 |
if (Stone *st = YieldStone(newp)) { |
if (!IsLevelBorder(newp)) { |
405 |
if (!st->is_kind("borderstone")) { |
if (Stone *st = YieldStone(newp)) { |
406 |
Stone *self = YieldStone(oldp); |
Stone *self = YieldStone(oldp); |
407 |
SetStone(newp, self); |
SetStone(newp, self); |
408 |
state = COME; |
state = COME; |
410 |
set_alarm(); |
set_alarm(); |
411 |
init_model(); |
init_model(); |
412 |
|
|
413 |
SetStone(oldp, new SwapStone(st, impulse.dir)); |
SetStone(oldp, new SwapStone(st, impulse.dir)); // sets alarm |
414 |
play_sound ("st-move"); |
play_sound ("st-move"); |
415 |
player::IncMoveCounter(2); |
player::IncMoveCounter(2); |
416 |
} |
} |
939 |
// When st-wood is created it randomly becomes st-wood1 or st-wood2. |
// When st-wood is created it randomly becomes st-wood1 or st-wood2. |
940 |
void on_creation() { |
void on_creation() { |
941 |
if (is_kind("st-wood")) { |
if (is_kind("st-wood")) { |
942 |
GridPos p = get_pos(); |
ReplaceStone(get_pos(), MakeStone(IntegerRand(0, 1) ? "st-wood1" : "st-wood2")); |
|
KillStone(p); |
|
|
SetStone(p, MakeStone(IntegerRand(0, 1) ? "st-wood1" : "st-wood2")); |
|
943 |
return; |
return; |
944 |
} |
} |
945 |
MovableStone::on_creation(); |
MovableStone::on_creation(); |
947 |
|
|
948 |
void fall() { |
void fall() { |
949 |
GridPos p = get_pos(); |
GridPos p = get_pos(); |
950 |
if (Floor *fl=GetFloor(p)) { |
if (!world::IsLevelBorder(p)) { |
951 |
const string &k = fl->get_kind(); |
if (Floor *fl=GetFloor(p)) { |
952 |
if (k == "fl-abyss" || k=="fl-water" || k=="fl-swamp") { |
const string &k = fl->get_kind(); |
953 |
if (!world::IsLevelBorder(p)) { |
if (k == "fl-abyss" || k=="fl-water" || k=="fl-swamp") { |
954 |
SetFloor(p, MakeFloor(is_kind("st-wood1") ? "fl-stwood1" : "fl-stwood2")); |
SetFloor(p, MakeFloor(is_kind("st-wood1") ? "fl-stwood1" : "fl-stwood2")); |
955 |
KillStone(p); |
KillStone(p); |
956 |
} |
} |
978 |
void init_model() { set_anim("st-wood-growing"); } |
void init_model() { set_anim("st-wood-growing"); } |
979 |
void animcb() { |
void animcb() { |
980 |
Stone *st = world::MakeStone("st-wood1"); |
Stone *st = world::MakeStone("st-wood1"); |
981 |
world::SetStone(get_pos(), st); |
world::ReplaceStone(get_pos(), st); |
982 |
} |
} |
983 |
}; |
}; |
984 |
} |
} |
1070 |
// :interval seconds between two "ticks" |
// :interval seconds between two "ticks" |
1071 |
// :loop |
// :loop |
1072 |
// :action,target as usual |
// :action,target as usual |
1073 |
|
// :invisible |
1074 |
//---------------------------------------- |
//---------------------------------------- |
1075 |
|
|
1076 |
/** \page st-timer Timer Stone |
/** \page st-timer Timer Stone |
1084 |
- \b interval: number of seconds before \b action is performed |
- \b interval: number of seconds before \b action is performed |
1085 |
- \b loop: if 1, restart the timer after performing \b action |
- \b loop: if 1, restart the timer after performing \b action |
1086 |
- \b action, \b target: as usual |
- \b action, \b target: as usual |
1087 |
|
- \b invisible : if 1, stone is invisible |
1088 |
|
|
1089 |
\subsection timerm Messages |
\subsection timerm Messages |
1090 |
|
|
1109 |
set_attrib("interval", 1.0); |
set_attrib("interval", 1.0); |
1110 |
set_attrib("loop", 1.0); |
set_attrib("loop", 1.0); |
1111 |
set_attrib("on", 1.0); |
set_attrib("on", 1.0); |
1112 |
|
set_attrib("invisible", 0.0); |
1113 |
|
|
1114 |
// set_on(true); DOESN'T WORK! calls init_model() |
// set_on(true); DOESN'T WORK! calls init_model() |
1115 |
} |
} |
1119 |
double_attrib("interval", &interval); |
double_attrib("interval", &interval); |
1120 |
return interval; |
return interval; |
1121 |
} |
} |
1122 |
void init_model() { set_model(is_on() ? "st-timer" : "st-timeroff"); } |
void init_model() { |
1123 |
|
if (int_attrib("invisible")) { |
1124 |
|
set_model("invisible"); |
1125 |
|
} |
1126 |
|
else { |
1127 |
|
set_model(is_on() ? "st-timer" : "st-timeroff"); |
1128 |
|
} |
1129 |
|
} |
1130 |
|
|
1131 |
void on_creation() { |
void on_creation() { |
1132 |
set_alarm(); |
set_alarm(); |