2
* Copyright (C) 2008,2009,2010 Ronald Lamprecht
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with this program; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "stones/PassageStone.hh"
27
PassageStone::PassageStone(int color, int flavor) : Stone() {
29
objFlags |= (flavor << 24);
32
std::string PassageStone::getClass() const {
36
void PassageStone::setAttr(const string& key, const Value &val) {
38
Stone::setAttr("state", val);
39
} else if (key == "flavor") {
40
std::string fs = val.to_string();
41
int fo = (objFlags & OBJBIT_FLAVOR) >> 24;
43
if (fs == "square") fi = 0;
44
else if (fs == "slash") fi = 1;
45
else if (fs == "cross") fi = 2;
46
else if (fs == "frame") fi = 3;
47
if (fi != -1 && fi !=fo) {
48
objFlags = (objFlags & ~OBJBIT_FLAVOR) | (fi << 24);
54
Stone::setAttr(key, val);
57
Value PassageStone::getAttr(const std::string &key) const {
60
} else if (key == "flavor") {
63
return Stone::getAttr(key);
66
Value PassageStone::message(const Message &m) {
67
if (m.message == "signal" || m.message == "_trigger") {
71
return Stone::message(m);
74
void PassageStone::init_model() {
75
set_model(ecl::strf("st_passage_%s_%s", (state == BLACK) ? "black" : "white", flavor().c_str()));
78
bool PassageStone::is_floating() const {
82
bool PassageStone::is_transparent (Direction d) const {
86
StoneResponse PassageStone::collision_response(const StoneContact &sc) {
87
Value accolor = sc.actor->getAttr("color");
89
if (server::GameCompatibility != GAMET_ENIGMA && sc.actor->getClass() != "ac_marble")
93
return (accolor && accolor == BLACK) ? STONE_PASS : STONE_REBOUND;
96
return (accolor && accolor == WHITE) ? STONE_PASS : STONE_REBOUND;
100
std::string PassageStone::flavor() const {
101
switch ((objFlags & OBJBIT_FLAVOR) >> 24) {
102
case 0 : return "square";
103
case 1 : return "slash";
104
case 2 : return "cross";
105
case 3 : return "frame";
107
ASSERT(false, XLevelRuntime, "PassageStone unknown flavor");
110
int PassageStone::traitsIdx() const {
111
return ((objFlags & OBJBIT_FLAVOR) >> 24) + 4 * state;
114
StoneTraits PassageStone::traits[8] = {
115
{"st_passage_black_square", st_passage_black_square, stf_transparent, material_stone, 1.0, MOVABLE_PERSISTENT},
116
{"st_passage_black_slash", st_passage_black_slash, stf_transparent, material_stone, 1.0, MOVABLE_PERSISTENT},
117
{"st_passage_black_cross", st_passage_black_cross, stf_transparent, material_stone, 1.0, MOVABLE_PERSISTENT},
118
{"st_passage_black_frame", st_passage_black_frame, stf_transparent, material_stone, 1.0, MOVABLE_PERSISTENT},
119
{"st_passage_white_square", st_passage_white_square, stf_transparent, material_stone, 1.0, MOVABLE_PERSISTENT},
120
{"st_passage_white_slash", st_passage_white_slash, stf_transparent, material_stone, 1.0, MOVABLE_PERSISTENT},
121
{"st_passage_white_cross", st_passage_white_cross, stf_transparent, material_stone, 1.0, MOVABLE_PERSISTENT},
122
{"st_passage_white_frame", st_passage_white_frame, stf_transparent, material_stone, 1.0, MOVABLE_PERSISTENT},
126
BootRegister(new PassageStone(BLACK, 0), "st_passage");
127
BootRegister(new PassageStone(BLACK, 0), "st_passage_black");
128
BootRegister(new PassageStone(BLACK, 0), "st_passage_black_square");
129
BootRegister(new PassageStone(BLACK, 1), "st_passage_black_slash");
130
BootRegister(new PassageStone(BLACK, 2), "st_passage_black_cross");
131
BootRegister(new PassageStone(BLACK, 3), "st_passage_black_frame");
132
BootRegister(new PassageStone(WHITE, 0), "st_passage_white");
133
BootRegister(new PassageStone(WHITE, 0), "st_passage_white_square");
134
BootRegister(new PassageStone(WHITE, 1), "st_passage_white_slash");
135
BootRegister(new PassageStone(WHITE, 2), "st_passage_white_cross");
136
BootRegister(new PassageStone(WHITE, 3), "st_passage_white_frame");
139
} // namespace enigma