~ubuntu-branches/ubuntu/trusty/enigma/trusty-proposed

« back to all changes in this revision

Viewing changes to src/stones/ShogunStone.cc

  • Committer: Package Import Robot
  • Author(s): Erich Schubert
  • Date: 2013-04-06 14:54:02 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130406145402-jgjrtk7hac8gtvza
Tags: 1.20-dfsg.1-1
* New upstream release (Closes: #704595)
  (Repacked: dropped zipios++ source and main menu music)
* Update watch file, sf.net again.
* Fix documentation links (Closes: #653508)
* Conflict with enigma-level-previews to encourage deinstallation
  (Pregenerated level previews were only used with version 1.01)
* Use dh7 for building instead of CDBS
* Update to policy 3.9.4.0 (no changes)
* Register documentation with doc-base

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * modify it under the terms of the GNU General Public License
6
6
 * as published by the Free Software Foundation; either version 2
7
7
 * of the License, or (at your option) any later version.
8
 
 *  
 
8
 *
9
9
 * This program is distributed in the hope that it will be useful,
10
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
27
    ShogunStone::ShogunStone(int holes) : Stone () {
28
28
        objFlags |= holes << 24;
29
29
    }
30
 
    
 
30
 
31
31
    ShogunStone* ShogunStone::clone() {
32
32
        return new ShogunStone(*this);
33
33
    }
34
 
    
 
34
 
35
35
    void ShogunStone::dispose() {
36
36
         if (subShogun != NULL) {
37
37
            SendMessage(subShogun, "disconnect");
45
45
    std::string ShogunStone::getClass() const {
46
46
        return "st_shogun";
47
47
    }
48
 
    
 
48
 
49
49
    void ShogunStone::setAttr(const string& key, const Value &val) {
50
50
        if (key == "flavor") {
51
51
            ASSERT(!isDisplayable(), XLevelRuntime, "ShogunStone: attempt to reflavor an existing shogun");
65
65
        }
66
66
        Stone::setAttr(key, val);
67
67
    }
68
 
    
 
68
 
69
69
    Value ShogunStone::getAttr(const string &key) const {
70
70
        if (key == "flavor") {
71
71
            std::string result;
81
81
        } else
82
82
            return Stone::getAttr(key);
83
83
    }
84
 
    
 
84
 
85
85
    Value ShogunStone::message(const Message &m) {
86
86
        if (m.message == "kill") {
87
87
            if (yieldShogun()) {
98
98
    void ShogunStone::setState(int extState) {
99
99
        // reject any write attempts
100
100
    }
101
 
    
 
101
 
102
102
    void ShogunStone::init_model() {
103
103
        set_model(ecl::strf("st_shogun%d", getHoles()/S));
104
104
    }
105
 
    
 
105
 
106
106
    void ShogunStone::setOwnerPos(GridPos po) {
107
107
        Stone::setOwnerPos(po);
108
108
        if (subShogun != NULL)
109
109
            subShogun->setOwnerPos(po);
110
110
    }
111
 
    
 
111
 
112
112
    void ShogunStone::on_creation(GridPos p) {
113
113
        Stone::on_creation(p);
114
114
        if (subShogun != NULL)
142
142
            }
143
143
        }
144
144
    }
145
 
    
 
145
 
146
146
    void ShogunStone::on_removal(GridPos p) {
147
147
        if (subShogun != NULL)
148
148
            subShogun->setOwnerPos(GridPos(-1,-1));
163
163
            if (nss != NULL)
164
164
                fitsNeighborShogun = (nss->getHoles() & (2*ownHole() -1)) == 0;
165
165
        }
166
 
        
 
166
 
167
167
        if ((subShogun == NULL) && ((st == NULL) || fitsNeighborShogun)) {  // can we move?
168
168
            // first remove from current position
169
169
            if (!yieldShogun())
170
170
                return;            // being swapped or pulled
171
 
            
 
171
 
172
172
            sound_event("movesmall");
173
 
            
 
173
 
174
174
            // then put to new position
175
175
            if (st == NULL) {
176
176
                SetStone(newPos, this);
185
185
                s->subShogun = this;
186
186
                superShogun = s;
187
187
 
188
 
                nss->init_model();     // display new hole         
 
188
                nss->init_model();     // display new hole
189
189
                setOwnerPos(newPos);   // the stone is owned at the new position
190
190
                TouchStone(newPos);
191
191
            }
192
 
            
 
192
 
193
193
            server::IncMoveCounter();
194
194
            ShatterActorsInsideField(newPos);
195
195
            if (server::GameCompatibility != GAMET_ENIGMA) {
196
196
                if (Item *it = GetItem(newPos)) {
197
 
                    ItemID id = get_id(it);
 
197
                    ItemID theid = get_id(it);
198
198
                    if ((server::GameCompatibility != GAMET_OXYD1 && server::GameCompatibility != GAMET_OXYDMAGNUM) ||
199
 
                            (id != it_cherry && id != it_bomb))
 
199
                            (theid != it_cherry && theid != it_bomb))
200
200
                        it->on_stonehit(this);
201
201
                }
202
202
            }
203
203
        }
204
204
        propagateImpulse(impulse);
205
205
    }
206
 
    
 
206
 
207
207
    int ShogunStone::getHoles() const {
208
208
        return (objFlags & OBJBIT_HOLES) >> 24;
209
209
    }
210
 
    
 
210
 
211
211
    int ShogunStone::ownHole() const {
212
212
        int holes = getHoles();
213
213
        for (int check = ShogunStone::U; check > 0; check = check >> 1)
214
214
            if (holes & check)
215
215
                return check;
216
 
        ASSERT(false, XLevelRuntime, "ShogunStone: internal error - no holes");
 
216
        throw XLevelRuntime("ShogunStone: internal error - no holes");
217
217
    }
218
 
    
 
218
 
219
219
    void ShogunStone::addSubHoles(int holes) {
220
220
        objFlags |= holes <<24;
221
221
    }
222
 
    
 
222
 
223
223
    void ShogunStone::removeSubHoles(int holes) {
224
224
        objFlags &= ~(holes <<24);
225
225
    }
226
 
    
 
226
 
227
227
    void ShogunStone::removeAllSubHoles() {
228
228
        int hole = ownHole();
229
229
        objFlags &= ~OBJBIT_HOLES;
230
230
        objFlags |= hole <<24;
231
231
    }
232
 
    
 
232
 
233
233
    bool ShogunStone::yieldShogun() {
234
234
        if (isDisplayable() && subShogun == NULL) {
235
235
            YieldStone(get_pos());
236
236
        } else if (isDisplayable()) {
237
237
            // top most shogun moved by wire or killed
238
 
            GridPos oldPos = get_pos(); 
 
238
            GridPos oldPos = get_pos();
239
239
            YieldStone(oldPos);
240
240
            subShogun->superShogun = NULL;
241
241
            SetStone(oldPos, subShogun);
246
246
            ShogunStone *oss = dynamic_cast<ShogunStone *>(GetStone(getOwnerPos()));
247
247
            if (oss == NULL)   // we are swapped or pulled and impulsed by wire
248
248
                return false;        // forget impulse
249
 
            
 
249
 
250
250
            ASSERT(superShogun != NULL, XLevelRuntime, "Shogun: missing super shogun");
251
251
            superShogun->subShogun = subShogun;
252
252
            superShogun->removeSubHoles(ownHole());
264
264
        }
265
265
        return true;
266
266
    }
267
 
    
 
267
 
268
268
    FreezeStatusBits ShogunStone::get_freeze_bits() {
269
269
        return (getHoles() == S) ? FREEZEBIT_STANDARD : FREEZEBIT_NO_STONE;
270
270
    }
271
 
    
 
271
 
272
272
    DEF_TRAITSM(ShogunStone, "st_shogun", st_shogun, MOVABLE_IRREGULAR);
273
 
    
 
273
 
274
274
    BOOT_REGISTER_START
275
275
        BootRegister(new ShogunStone(4), "st_shogun");
276
276
        BootRegister(new ShogunStone(4), "st_shogun_s");