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

« back to all changes in this revision

Viewing changes to src/items/SimpleItems.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
32
32
 
33
33
    Banana::Banana() {
34
34
    }
35
 
    
 
35
 
36
36
    void Banana::processLight(Direction d) {
37
37
        sound_event("itemtransform");
38
38
        transform("it_cherry");
46
46
 
47
47
 
48
48
/* -------------------- Brush -------------------- */
49
 
   
 
49
 
50
50
    Brush::Brush() {
51
51
    }
52
 
    
 
52
 
53
53
    ItemAction Brush::activate(Actor *a, GridPos p) {
54
54
        if (Item *it = GetItem(p))
55
55
            SendMessage (it, "_brush");
56
56
        return ITEM_DROP;
57
57
    }
58
 
    
 
58
 
59
59
    DEF_ITEMTRAITSF(Brush, "it_brush", it_brush, itf_inflammable);
60
60
 
61
61
/* -------------------- Cherry -------------------- */
62
62
 
63
63
    Cherry::Cherry() {
64
64
    }
65
 
    
 
65
 
66
66
    ItemAction Cherry::activate(Actor *actor, GridPos p) {
67
67
        if (SendMessage(actor, "_invisibility").to_bool())
68
68
            return ITEM_KILL;
74
74
    void Cherry::on_stonehit(Stone *) {
75
75
        transform("it_squashed");
76
76
    }
77
 
    
 
77
 
78
78
    void Cherry::on_drop(Actor *a) {
79
 
        transform("it_squashed");        
 
79
        transform("it_squashed");
80
80
    }
81
81
 
82
82
    DEF_ITEMTRAITS(Cherry, "it_cherry", it_cherry);
83
83
 
84
84
/* -------------------- Death Item  -------------------- */
85
 
    
 
85
 
86
86
    DeathItem::DeathItem() {
87
87
    }
88
 
    
89
 
    void DeathItem::animcb() { 
90
 
        set_model("it_death"); 
 
88
 
 
89
    void DeathItem::animcb() {
 
90
        set_model("it_death");
91
91
        state = 0;
92
92
     }
93
93
 
102
102
        }
103
103
        return false;
104
104
    }
105
 
    
 
105
 
106
106
    DEF_ITEMTRAITSF(DeathItem, "it_death", it_death, itf_static | itf_indestructible);
107
107
 
108
108
/* -------------------- Debris -------------------- */
110
110
    Debris::Debris(int type) {
111
111
        state = type;
112
112
    }
113
 
    
114
 
    void Debris::animcb() { 
 
113
 
 
114
    void Debris::animcb() {
115
115
        SetFloor(get_pos(), MakeFloor(state == 0 ? "fl_abyss" : "fl_water"));
116
116
        kill();
117
117
     }
124
124
    int Debris::traitsIdx() const {
125
125
        return ecl::Clamp<int>(state, 0, 1);
126
126
    }
127
 
    
 
127
 
128
128
    ItemTraits Debris::traits[2] = {
129
129
        {"it_debris", it_debris,  itf_static | itf_animation | itf_indestructible | itf_fireproof, 0.0},
130
130
        {"it_debris_water", it_debris_water,  itf_static | itf_animation | itf_indestructible | itf_fireproof, 0.0},
131
131
    };
132
 
    
 
132
 
133
133
/* -------------------- Explosion -------------------- */
134
134
 
135
135
    Explosion::Explosion(int strength) {
136
136
        state = strength;
137
137
    }
138
 
    
 
138
 
139
139
    std::string Explosion::getClass() const {
140
140
        return "it_explosion";
141
141
    }
150
150
        }
151
151
        return Item::message(m);
152
152
    }
153
 
    
 
153
 
154
154
    void Explosion::setState(int extState) {
155
155
        // no state writes
156
156
    }
157
 
    
 
157
 
158
158
    void Explosion::init_model() {
159
159
        set_anim("it_explosion");
160
160
    }
161
 
    
162
 
    void Explosion::animcb() { 
 
161
 
 
162
    void Explosion::animcb() {
163
163
        Floor *fl = GetFloor(get_pos());
164
164
        if (state != 0 && fl->is_destructible())
165
165
            if (state == 1)
172
172
                    isAbyss = false;
173
173
                else if (server::SubSoil == 2) {
174
174
                    for (Direction d = NORTH; d != NODIR; d = previous(d)) {
175
 
                        Floor *fl = GetFloor(move(get_pos(), d));
176
 
                        if (fl != NULL && fl->getClass() == "fl_water") {
 
175
                        Floor *thefl = GetFloor(move(get_pos(), d));
 
176
                        if (thefl != NULL && thefl->getClass() == "fl_water") {
177
177
                            isAbyss = false;
178
178
                            break;
179
179
                        }
189
189
        SendMessage(actor, "_shatter");
190
190
        return false;
191
191
    }
192
 
     
 
192
 
193
193
    int Explosion::traitsIdx() const {
194
194
        return ecl::Clamp<int>(state, 0, 3);
195
195
    }
196
 
    
 
196
 
197
197
    ItemTraits Explosion::traits[4] = {
198
198
        {"it_explosion_nil",  it_explosion_nil, itf_static | itf_animation | itf_indestructible | itf_norespawn | itf_fireproof, 0.0},
199
199
        {"it_explosion_hollow",  it_explosion_hollow, itf_static | itf_animation | itf_indestructible | itf_norespawn | itf_fireproof, 0.0},
206
206
    FlagItem::FlagItem(int type) {
207
207
        Item::setAttr("color", type);
208
208
    }
209
 
    
 
209
 
210
210
    std::string FlagItem::getClass() const {
211
211
        return "it_flag";
212
212
    }
213
 
    
 
213
 
214
214
    void FlagItem::setAttr(const string& key, const Value &val) {
215
215
        if (key == "color") {
216
216
            if ((int)val < 0 || (int)val > 1)
217
217
                return;
218
218
        }
219
219
        Item::setAttr(key, val);
220
 
    }        
 
220
    }
221
221
    void FlagItem::on_drop(Actor *a) {
222
222
        player::SetRespawnPositions(get_pos(), getAttr("color"));
223
223
    }
224
 
    
 
224
 
225
225
    void FlagItem::on_pickup(Actor *a) {
226
226
        player::RemoveRespawnPositions(getAttr("color"));
227
227
    }
228
 
    
 
228
 
229
229
    int FlagItem::traitsIdx() const {
230
230
        return getAttr("color");
231
231
    }
232
 
    
 
232
 
233
233
    ItemTraits FlagItem::traits[2] = {
234
234
        {"it_flag_black", it_flag_black,  itf_none, 0.0},
235
235
        {"it_flag_white", it_flag_white,  itf_none, 0.0},
239
239
 
240
240
    Key::Key() {
241
241
    }
242
 
    
 
242
 
243
243
    void Key::setAttr(const string& key, const Value &val) {
244
244
        Item::setAttr(key, val);
245
245
        if (key == "invisible" || key == "code") {
246
246
            player::RedrawInventory();
247
247
        }
248
248
    }
249
 
    
 
249
 
250
250
    std::string Key::get_inventory_model() {
251
251
        bool showCode = !getAttr("invisible").to_bool();
252
252
        int code = getAttr("code");
253
253
        if (showCode && code >= 1 && code <= 8)
254
254
            return ecl::strf("it_key_%d", code);
255
255
        else
256
 
            return "it_key";        
 
256
            return "it_key";
257
257
    }
258
 
    
 
258
 
259
259
    DEF_ITEMTRAITS(Key, "it_key", it_key);
260
 
    
 
260
 
261
261
/* -------------------- Pencil -------------------- */
262
262
 
263
263
    Pencil::Pencil() {
264
264
    }
265
 
    
 
265
 
266
266
    ItemAction Pencil::activate(Actor *a, GridPos p) {
267
267
        if (enigma_server::GameCompatibility == GAMET_ENIGMA) {
268
 
            if (Item *it=GetItem(p)) {
 
268
            if (GetItem(p))
269
269
                return ITEM_KEEP;
270
 
            }
271
270
            // If the actor is flying and tries to make a cross, drop the it-pencil
272
 
            if (a->is_flying()) {
 
271
            if (a->is_flying())
273
272
                return ITEM_DROP;
274
 
            }
275
273
 
276
274
            Floor *fl = GetFloor(p);
277
275
            std::string floor = fl->getClass();
294
292
        }
295
293
        return ITEM_KEEP;
296
294
    }
297
 
    
 
295
 
298
296
    DEF_ITEMTRAITS(Pencil, "it_pencil", it_pencil);
299
 
    
 
297
 
300
298
/* -------------------- Pin -------------------- */
301
299
    Pin::Pin() {
302
300
    }
303
 
    
 
301
 
304
302
    void Pin::setOwner(int player) {
305
303
        Value oldPlayer = getOwner();
306
304
        Item::setOwner(player);
307
305
        if (oldPlayer.getType() != Value::NIL && oldPlayer != -1 ) {
308
 
            BroadcastMessage("_update_pin", oldPlayer, GRID_NONE_BIT, true);            
 
306
            BroadcastMessage("_update_pin", oldPlayer, GRID_NONE_BIT, true);
309
307
        }
310
308
        if (player != -1) {
311
309
            BroadcastMessage("_update_pin", player, GRID_NONE_BIT, true);
316
314
 
317
315
    Ring::Ring() {
318
316
    }
319
 
    
 
317
 
320
318
    ItemAction Ring::activate(Actor *a, GridPos p) {
321
319
        if (a->isMoribund())
322
320
            return ITEM_KEEP;
337
335
 
338
336
    Spade::Spade() {
339
337
    }
340
 
    
 
338
 
341
339
    ItemAction Spade::activate(Actor *a, GridPos p) {
342
340
        if (Item *it=GetItem(p)) {
343
341
            sound::EmitSoundEvent("spade", p.center());
353
351
 
354
352
    Spoon::Spoon() {
355
353
    }
356
 
    
 
354
 
357
355
    ItemAction Spoon::activate(Actor *a, GridPos) {
358
356
        SendMessage(a, "_suicide");
359
357
        return ITEM_DROP;
365
363
    Spring::Spring(int type) {
366
364
        state = type;
367
365
    }
368
 
    
 
366
 
369
367
    std::string Spring::getClass() const {
370
368
        return "it_spring";
371
369
    }
372
370
    void Spring::setState(int extState) {
373
371
        // block all write attempts
374
372
    }
375
 
    
 
373
 
376
374
    ItemAction Spring::activate(Actor *a, GridPos p) {
377
375
        if (state == KEEP) {
378
376
            SendMessage(a, "_jump");
387
385
                return ITEM_KEEP;
388
386
            }
389
387
        }
 
388
        return ITEM_KEEP;
390
389
    }
391
 
    
 
390
 
392
391
    int Spring::traitsIdx() const {
393
392
        return ecl::Clamp<int>(state, 0, 1);
394
393
    }
395
 
    
 
394
 
396
395
    ItemTraits Spring::traits[2] = {
397
396
        {"it_spring_keep", it_spring_keep,  itf_none, 0.0},
398
397
        {"it_spring_drop", it_spring_drop,  itf_none, 0.0},
401
400
/* -------------------- Springboard -------------------- */
402
401
    Springboard::Springboard() {
403
402
    }
404
 
    
 
403
 
405
404
    bool Springboard::actor_hit(Actor *a) {
406
405
        const double MAXDIST = 0.3;
407
406
        double ycenter = get_pos().y + 0.5;
419
418
    }
420
419
 
421
420
    DEF_ITEMTRAITSF(Springboard, "it_springboard", it_springboard, itf_static | itf_portable | itf_freezable);
422
 
    
 
421
 
423
422
/* -------------------- Squashed Cherry -------------------- */
424
423
 
425
424
    Squashed::Squashed() {
426
425
    }
427
 
    
 
426
 
428
427
    Value Squashed::message (const Message &m) {
429
428
        if (enigma_server::GameCompatibility == GAMET_ENIGMA) {
430
429
            if (m.message == "_brush" || m.message == "_freeze") {
440
439
/* -------------------- Weight item -------------------- */
441
440
    Weight::Weight() {
442
441
    }
443
 
    
 
442
 
444
443
    void Weight::setAttr(const string& key, const Value &val) {
445
444
        if (key == "mass") {
446
445
            double oldMass = getAttr("mass");
457
456
            return;
458
457
        }
459
458
        Item::setAttr(key, val);
460
 
    }        
461
 
        
 
459
    }
 
460
 
462
461
    void Weight::setOwner(int player) {
463
462
        Value oldPlayer = getOwner();
464
463
        if (player == -1) {
470
469
        if (oldPlayer.getType() != Value::NIL && oldPlayer != -1 ) {
471
470
            Inventory *i = player::GetInventory(oldPlayer);
472
471
            i->setAttr("mass", (double)i->getAttr("mass") - (double)getAttr("mass"));
473
 
            BroadcastMessage("_update_mass", oldPlayer, GRID_NONE_BIT, true);            
 
472
            BroadcastMessage("_update_mass", oldPlayer, GRID_NONE_BIT, true);
474
473
        }
475
474
        if (player != -1) {
476
475
            Inventory *i = player::GetInventory(player);
483
482
        Item::on_creation(p);
484
483
        SendMessage(GetFloor(p), "_add_mass", getAttr("mass"), this);
485
484
    }
486
 
    
 
485
 
487
486
    void Weight::on_removal(GridPos p) {
488
487
        SendMessage(GetFloor(get_pos()), "_add_mass", -(double)getAttr("mass"), this);
489
488
        Item::on_removal(p);
490
489
    }
491
 
    
 
490
 
492
491
    void Weight::setOwnerPos(GridPos po) {
493
492
        if (po == GridPos(-1, -1)) {
494
493
            GridPos p = getOwnerPos();
496
495
                SendMessage(GetFloor(p), "_add_mass", -(double)getAttr("mass"), this);
497
496
        }
498
497
        Item::setOwnerPos(po);
499
 
        SendMessage(GetFloor(po), "_add_mass", getAttr("mass"), this);        
 
498
        SendMessage(GetFloor(po), "_add_mass", getAttr("mass"), this);
500
499
    }
501
 
    
 
500
 
502
501
    ItemAction Weight::activate(Actor *, GridPos p) {
503
502
        return ITEM_KEEP;
504
503
    }
505
 
    
 
504
 
506
505
    DEF_ITEMTRAITS(Weight, "it_weight", it_weight);
507
506
 
508
507
/* -------------------- YinYang item -------------------- */
509
508
    Yinyang::Yinyang() {
510
509
    }
511
 
    
 
510
 
512
511
    std::string Yinyang::get_inventory_model() {
513
512
        if (player::CurrentPlayer() == 0)
514
513
            return "it_yinyang";
515
514
        else
516
515
            return "it_yangyin";
517
516
    }
518
 
    
 
517
 
519
518
    ItemAction Yinyang::activate(Actor *a, GridPos p) {
520
519
        // Switch to other marble
521
520
        player::SwapPlayers();
522
521
        sound::EmitSoundEvent("switchplayer", p.center());
523
522
        return ITEM_KEEP;
524
523
    }
525
 
    
 
524
 
526
525
    DEF_ITEMTRAITS(Yinyang, "it_yinyang", it_yinyang);
527
526
 
528
527