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

« back to all changes in this revision

Viewing changes to src/items/Trigger.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:
6
6
 * modify it under the terms of the GNU General Public License
7
7
 * as published by the Free Software Foundation; either version 2
8
8
 * of the License, or (at your option) any later version.
9
 
 *  
 
9
 *
10
10
 * This program is distributed in the hope that it will be useful,
11
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
31
    Trigger::Trigger() {
32
32
        setAttr("invisible", false);
33
33
    }
34
 
    
 
34
 
35
35
    Value Trigger::message (const Message &m) {
36
 
        if (m.message == "signal" && (server::GameCompatibility != GAMET_ENIGMA || 
 
36
        if (m.message == "signal" && (server::GameCompatibility != GAMET_ENIGMA ||
37
37
                server::EnigmaCompatibility < 1.10)) {
38
38
            performAction(m.value.to_bool());  // convert 1/0 values to true/false
39
39
            return Value();
43
43
            // actor_enter due to actors on_creation.
44
44
            // Thus we need to reset and recount the actors:
45
45
            state = 0;
46
 
            
 
46
 
47
47
            // old Enigma versions did issue performAction what is incompatible
48
 
            int id = getId();
 
48
            int theid = getId();
49
49
            updateIState(countActors(),
50
 
                    server::EnigmaCompatibility >= 1.10 || server::GameCompatibility != GAMET_ENIGMA); 
51
 
            if (Object::getObject(id) != NULL)   // not killed?
 
50
                    server::EnigmaCompatibility >= 1.10 || server::GameCompatibility != GAMET_ENIGMA);
 
51
            if (Object::getObject(theid) != NULL)   // not killed?
52
52
                init_model();
53
53
            return Value();
54
54
        } else if (m.message == "_jumping" ) {
64
64
        }
65
65
        return Item::message(m);
66
66
    }
67
 
        
 
67
 
68
68
    int Trigger::externalState() const {
69
69
        return state != 0 ? 1 : 0;
70
70
    }
71
 
    
 
71
 
72
72
    void Trigger::setState(int extState) {
73
73
        return;   // ignore any write attempts
74
74
    }
75
 
    
 
75
 
76
76
    void Trigger::on_creation(GridPos p) {
77
77
        state = 0;
78
 
        int id = getId();
 
78
        int theid = getId();
79
79
        updateIState(countActors(), true);
80
 
        if (Object::getObject(id) != NULL)   // not killed?
 
80
        if (Object::getObject(theid) != NULL)   // not killed?
81
81
            init_model();
82
82
    }
83
 
        
 
83
 
84
84
    void Trigger::init_model() {
85
85
        if (getAttr("invisible").to_bool())
86
86
            set_model("invisible");
89
89
        else
90
90
            set_model("it_trigger_up");
91
91
    }
92
 
    
 
92
 
93
93
    void Trigger::actor_enter(Actor *a) {
94
94
        if (!(a->is_flying() || a->isMoribund()))
95
95
            updateIState(+1, !server::WorldInitialized);
96
96
    }
97
 
    
 
97
 
98
98
    void Trigger::actor_leave(Actor *a) {
99
99
        if (!(a->is_flying() || a->isMoribund()))
100
100
            updateIState(-1, !server::WorldInitialized);
101
101
    }
102
 
    
 
102
 
103
103
    void Trigger::stone_change(Stone *) {
104
104
        updateIState(0);
105
105
    }
106
 
    
 
106
 
107
107
    int Trigger::countActors() {
108
108
        std::vector<Actor*> actors;
109
109
        GetActorsInsideField(get_pos(), actors);
112
112
            if (!((*itr)->is_flying() || (*itr)->isMoribund())) count++;
113
113
        return count;
114
114
    }
115
 
    
 
115
 
116
116
    void Trigger::updateIState(int diffActors, bool refuseAction) {
117
117
        int oldState = state;
118
 
        
 
118
 
119
119
        state += 2 * diffActors;
120
 
        
 
120
 
121
121
        Stone *st = GetStone(get_pos());
122
122
        state &= ~1;  // delete stone pressure bit
123
123
        if (st != NULL && (!st->is_floating() || st->getClass() == "st_puzzle")) {
124
124
            // Hack to make hollow puzzle stones press triggers
125
125
            state |= 1;   // add stone pressure bit
126
126
        }
127
 
                
 
127
 
128
128
//        Log << "Trigger update old state " << oldState << " - new state " << state << " refuse action " << refuseAction << "\n";
129
 
    
 
129
 
130
130
        if ((oldState == 0 && state != 0) || (oldState != 0 && state == 0)) {
131
131
            init_model();
132
132
            if (!refuseAction) {