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

« back to all changes in this revision

Viewing changes to src/stones/StoneImpulse.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
24
24
#include "world.hh"
25
25
 
26
26
namespace enigma {
27
 
    StoneImpulse::StoneImpulse(bool isSteady, bool isHollow, bool isMovable, bool isActive) : Stone () {
28
 
        if (isSteady)
 
27
    StoneImpulse::StoneImpulse(bool isSteadyStone, bool isHollowStone, bool isMovableStone, bool isActiveStone) : Stone () {
 
28
        if (isSteadyStone)
29
29
            objFlags |= OBJBIT_STEADY;
30
 
        if (isHollow)
 
30
        if (isHollowStone)
31
31
            objFlags |= OBJBIT_HOLLOW;
32
 
        if (isMovable)
 
32
        if (isMovableStone)
33
33
            objFlags |= OBJBIT_MOVABLE;
34
 
        if (isActive)
 
34
        if (isActiveStone)
35
35
            state = EXPANDING;
36
36
    }
37
37
 
38
38
    std::string StoneImpulse::getClass() const {
39
39
        return "st_stoneimpulse";
40
40
    }
41
 
        
 
41
 
42
42
    void StoneImpulse::setAttr(const string& key, const Value &val) {
43
43
        if (key == "hollow") {
44
44
            if (!isDisplayable()) {
73
73
        } else
74
74
            Stone::setAttr(key, val);
75
75
    }
76
 
    
 
76
 
77
77
    Value StoneImpulse::getAttr(const std::string &key) const {
78
78
        if (key == "hollow") {
79
79
            return isHollow();
84
84
        } else
85
85
            return Stone::getAttr(key);
86
86
    }
87
 
    
 
87
 
88
88
    Value StoneImpulse::message(const Message &m) {
89
89
        if (m.message == "_trigger" && m.value.to_bool()) {
90
90
            Direction incoming = NODIR;
91
91
            if (m.sender != NULL)
92
92
                incoming = direction_fromto(dynamic_cast<GridObject *>(m.sender)->get_pos(), get_pos());
93
 
            
 
93
 
94
94
            if (state == IDLE && incoming != NODIR) {
95
95
                objFlags |= OBJBIT_NOBACKFIRE;
96
96
            }
97
97
            setIState(EXPANDING, incoming);
98
98
            return Value();
99
 
        } else if (m.message == "signal" && (to_double(m.value) != 0 || 
 
99
        } else if (m.message == "signal" && (to_double(m.value) != 0 ||
100
100
                (server::EnigmaCompatibility < 1.10 /*&& m.value.getType() == Value::NIL*/))) { // hack for old trigger without value
101
101
            setIState(EXPANDING);
102
102
            return Value();
131
131
        } else
132
132
            return Stone::message(m);
133
133
    }
134
 
    
135
 
            
 
134
 
 
135
 
136
136
    void StoneImpulse::setState(int extState) {
137
137
        // block any write attempts
138
138
    }
146
146
            set_anim(ecl::strf("st_stoneimpulse%s_anim%d", isHollow() ? "_hollow" : "",
147
147
                    state == EXPANDING ? 1 : 2));
148
148
    }
149
 
    
 
149
 
150
150
    void StoneImpulse::on_creation(GridPos p) {
151
151
        updateCurrentLightDirs();
152
 
            
 
152
 
153
153
        if (!isHollow())
154
154
            activatePhoto();
155
 
        
 
155
 
156
156
        if (state == IDLE && (objFlags & OBJBIT_STEADY) && (objFlags & OBJBIT_LIGHTNEWDIRS))
157
157
            setIState(EXPANDING);
158
158
        else if (!(objFlags & OBJBIT_STEADY) && !(objFlags & OBJBIT_LIGHTNEWDIRS))  // being swapped out of light
159
 
            objFlags &= ~OBJBIT_LASERIDLE;    
 
159
            objFlags &= ~OBJBIT_LASERIDLE;
160
160
 
161
161
        Stone::on_creation(p);
162
162
    }
163
 
    
 
163
 
164
164
    void StoneImpulse::lightDirChanged(DirectionBits oldDirs, DirectionBits newDirs) {
165
165
        if (added_dirs(oldDirs, newDirs) != NODIRBIT) {
166
 
            setIState(EXPANDING);            
 
166
            setIState(EXPANDING);
167
167
        }
168
168
    }
169
169
 
180
180
                objFlags |= OBJBIT_LASERIDLE;
181
181
        }
182
182
    }
183
 
    
 
183
 
184
184
    bool StoneImpulse::is_floating() const {
185
185
        return isHollow();
186
186
    }
187
 
    
 
187
 
188
188
    StoneResponse StoneImpulse::collision_response(const StoneContact &sc) {
189
189
        return ((state != IDLE) || !isHollow()) ? STONE_REBOUND : STONE_PASS;
190
190
    }
191
 
    
 
191
 
192
192
    void StoneImpulse::actor_inside(Actor *a) {
193
193
        if ((state != IDLE) && isHollow())
194
194
            SendMessage(a, "_shatter");
195
195
    }
196
 
    
 
196
 
197
197
    void StoneImpulse::actor_hit(const StoneContact &sc) {
198
198
        if (state != BREAKING) {
199
199
            if ((objFlags & OBJBIT_MOVABLE) && maybe_push_stone(sc))
200
200
                return;                                      // stone did move on impulse
201
 
            else if (!isHollow()) 
 
201
            else if (!isHollow())
202
202
                sc.actor->send_impulse(sc.stonepos, NODIR);  // impulse on the slightest touch
203
203
        }
204
204
    }
206
206
    void StoneImpulse::on_impulse(const Impulse& impulse) {
207
207
        if (state == BREAKING)
208
208
            return;
209
 
            
 
209
 
210
210
        Actor *hitman = NULL;
211
211
        if ((objFlags & OBJBIT_MOVABLE) && (impulse.dir != NODIR)) {
212
212
            // move stone without disturbing a running animation
215
215
            bool didMove = move_stone(impulse.dir);
216
216
            state = oldState;
217
217
            display::SetModel(GridLoc(GRID_STONES, get_pos()), yieldedModel);
218
 
            
 
218
 
219
219
            // pulse only if not pushed with a wand
220
220
            hitman = dynamic_cast<Actor*>(impulse.sender);
221
221
            if (hitman == NULL || !player::WieldedItemIs(hitman, "it_magicwand")) {
223
223
                    setIState(EXPANDING, impulse.dir);
224
224
                else if (didMove && state != EXPANDING) {
225
225
                    // ensure that an impulse to neighbors will be emitted when moved
226
 
                    Stone::setAttr("$incoming", impulse.dir); 
 
226
                    Stone::setAttr("$incoming", impulse.dir);
227
227
                    objFlags |= OBJBIT_REPULSE;
228
228
                }
229
229
            } else if (((objFlags & OBJBIT_STEADY) && (objFlags & OBJBIT_LIGHTNEWDIRS) && state == IDLE)) {
232
232
        } else {
233
233
            setIState(EXPANDING, impulse.dir);
234
234
        }
235
 
        
 
235
 
236
236
        // direct impulse propagation
237
 
        if (objFlags & OBJBIT_MOVABLE && (impulse.dir != NODIR)) { 
 
237
        if (objFlags & OBJBIT_MOVABLE && (impulse.dir != NODIR)) {
238
238
            if (hitman != NULL) {
239
239
                objFlags &= ~OBJBIT_PROPAGATE;
240
240
                propagateImpulse(impulse);
243
243
        }
244
244
        setAttr("$impulse_source", impulse.sender->getId());
245
245
    }
246
 
    
 
246
 
247
247
    FreezeStatusBits StoneImpulse::get_freeze_bits() {
248
248
        return FREEZEBIT_NO_STONE;
249
249
    }
250
 
    
 
250
 
251
251
    void StoneImpulse::setIState(int newState, Direction incoming) {
252
252
        if (newState != state && isDisplayable() && state != BREAKING) {
253
253
            switch (newState) {
282
282
                            send_impulse(move(p, d), d);
283
283
                    }
284
284
                    if (!(objFlags & OBJBIT_MOVABLE) || (objFlags & OBJBIT_PROPAGATE)) {
285
 
                        propagateImpulse(Impulse(this, GridPos(-1,-1), 
 
285
                        propagateImpulse(Impulse(this, GridPos(-1,-1),
286
286
                                to_direction(getAttr("$incoming"))));
287
287
                    }
288
288
                    objFlags &= ~OBJBIT_PROPAGATE;
290
290
            }
291
291
        }
292
292
    }
293
 
    
 
293
 
294
294
    void StoneImpulse::propagateImpulse(const Impulse& impulse) {
295
295
        if (!impulse.byWire && impulse.dir != NODIR) {
296
296
            ObjectList olist = getAttr("fellows");
305
305
        }
306
306
        setAttr("$impulse_source", 0);
307
307
    }
308
 
    
 
308
 
309
309
    bool StoneImpulse::isHollow() const {
310
310
        return (bool)(objFlags & OBJBIT_HOLLOW) && !(bool)(objFlags & OBJBIT_MOVABLE);
311
311
    }
312
 
    
 
312
 
313
313
    int StoneImpulse::traitsIdx() const {
314
314
        if (objFlags & OBJBIT_MOVABLE)
315
315
            return 3;
321
321
            return 0;
322
322
    }
323
323
 
324
 
    
 
324
 
325
325
    StoneTraits StoneImpulse::traits[4] = {
326
326
        {"st_stoneimpulse", st_stoneimpulse, stf_none, material_stone, 1.0, MOVABLE_PERSISTENT},
327
327
        {"st_stoneimpulse_steady", st_stoneimpulse_steady, stf_none, material_stone, 1.0, MOVABLE_PERSISTENT},
328
328
        {"st_stoneimpulse_hollow", st_stoneimpulse_hollow, stf_none, material_stone, 1.0, MOVABLE_PERSISTENT},
329
329
        {"st_stoneimpulse_movable", st_stoneimpulse_movable, stf_none, material_stone, 1.0, MOVABLE_STANDARD},
330
330
    };
331
 
    
 
331
 
332
332
    BOOT_REGISTER_START
333
333
        BootRegister(new StoneImpulse(false, false, false, false), "st_stoneimpulse");
334
334
        BootRegister(new StoneImpulse(true,  false, false, false), "st_stoneimpulse_steady");