~ubuntu-branches/ubuntu/saucy/enigma/saucy

« back to all changes in this revision

Viewing changes to src/stones/PassageStone.cc

  • Committer: Bazaar Package Importer
  • Author(s): Erich Schubert
  • Date: 2010-05-26 02:27:26 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100526022726-7tnbf65s6btbibu2
Tags: 1.10~~pre-alpha+r2100-1
* New SVN checkout, shortly after upstream "pre-alpha" release
* Target unstable, to get more testing for enigma
* Remove spelling patches included upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008,2009,2010 Ronald Lamprecht
 
3
 *
 
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.
 
8
 *  
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 */
 
19
 
 
20
#include "stones/PassageStone.hh"
 
21
 
 
22
#include "errors.hh"
 
23
//#include "main.hh"
 
24
 
 
25
namespace enigma {
 
26
 
 
27
    PassageStone::PassageStone(int color, int flavor) : Stone() {
 
28
        state = color;
 
29
        objFlags |= (flavor << 24);
 
30
    }
 
31
    
 
32
    std::string PassageStone::getClass() const {
 
33
        return "st_passage";
 
34
    }
 
35
    
 
36
    void PassageStone::setAttr(const string& key, const Value &val) {
 
37
        if (key == "color") {
 
38
            Stone::setAttr("state", val);
 
39
        } else if (key == "flavor") {
 
40
            std::string fs = val.to_string();
 
41
            int fo = (objFlags & OBJBIT_FLAVOR) >> 24;
 
42
            int fi = -1;
 
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);
 
49
                if (isDisplayable())
 
50
                    init_model();
 
51
            }
 
52
            return;
 
53
        } else
 
54
            Stone::setAttr(key, val);
 
55
    }
 
56
    
 
57
    Value PassageStone::getAttr(const std::string &key) const {
 
58
        if (key == "color") {
 
59
            return state;
 
60
        } else if (key == "flavor") {
 
61
            return flavor();
 
62
        }
 
63
        return Stone::getAttr(key);
 
64
    }
 
65
    
 
66
    Value PassageStone::message(const Message &m) {
 
67
        if (m.message == "signal" || m.message == "_trigger") {
 
68
            toggleState();
 
69
            return Value();
 
70
        }
 
71
        return Stone::message(m);
 
72
    }
 
73
    
 
74
    void PassageStone::init_model()  {
 
75
        set_model(ecl::strf("st_passage_%s_%s", (state == BLACK) ? "black" : "white", flavor().c_str()));
 
76
    }
 
77
 
 
78
    bool PassageStone::is_floating() const {
 
79
        return true;
 
80
    }
 
81
    
 
82
    bool PassageStone::is_transparent (Direction d) const {
 
83
        return true;
 
84
    }
 
85
    
 
86
    StoneResponse PassageStone::collision_response(const StoneContact &sc) {
 
87
        Value accolor = sc.actor->getAttr("color"); 
 
88
        
 
89
        if (server::GameCompatibility != GAMET_ENIGMA && sc.actor->getClass() != "ac_marble")
 
90
            return STONE_REBOUND;
 
91
            
 
92
        if (state == BLACK) {
 
93
            return (accolor && accolor == BLACK) ?  STONE_PASS : STONE_REBOUND;
 
94
        }
 
95
        else {
 
96
            return (accolor && accolor == WHITE) ?  STONE_PASS : STONE_REBOUND;
 
97
        }
 
98
    }
 
99
    
 
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";
 
106
        }
 
107
        ASSERT(false, XLevelRuntime, "PassageStone unknown flavor");
 
108
    }
 
109
 
 
110
    int PassageStone::traitsIdx() const {
 
111
        return ((objFlags & OBJBIT_FLAVOR) >> 24) + 4 * state;
 
112
    }
 
113
 
 
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},
 
123
    };
 
124
    
 
125
    BOOT_REGISTER_START
 
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");
 
137
    BOOT_REGISTER_END
 
138
 
 
139
} // namespace enigma