~ubuntu-branches/ubuntu/edgy/enigma/edgy-backports

« back to all changes in this revision

Viewing changes to src/stones_internal.hh

  • Committer: Bazaar Package Importer
  • Author(s): Erich Schubert
  • Date: 2005-08-28 15:30:09 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050828153009-sky64kb6tcq37xt5
Tags: 0.92.1-1
* New upstream subversion checkout
* Remove menu.s3m, which we are allowed to distributed but not to modify
  also copyright notice is confusing... (Closes: #321669)
* Rebuild with new libzipios (Closes: #325405)
  I hope this works without a versioned build-dependency
* Added "enigma replaces enigma-data" for upgrades (Closes: #308558)
* Added notes about the fonts copyright.
* updated to policy 3.6.2.1 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2002,2003,2004 Daniel Heck
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
 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17
 
 *
18
 
 * $Id: stones_internal.hh,v 1.9 2004/03/18 18:09:24 dheck Exp $
19
 
 */
20
 
#ifndef STONES_INTERNAL_HH_INCLUDED
21
 
#define STONES_INTERNAL_HH_INCLUDED
22
 
 
23
 
#include "world.hh"
24
 
 
25
 
#define DECL_TRAITS                                              \
26
 
        static StoneTraits traits;                               \
27
 
        const StoneTraits &get_traits() const { return traits; }
28
 
 
29
 
#define DECL_TRAITS_ARRAY(n, subtype_expr)                                      \
30
 
        static StoneTraits traits[n];                                            \
31
 
        const StoneTraits &get_traits() const { return traits[subtype_expr]; }
32
 
 
33
 
#define DEF_TRAITS(classname, name, id)         \
34
 
    StoneTraits classname::traits = { name, id, stf_none, material_stone, 1.0 }
35
 
 
36
 
 
37
 
 
38
 
namespace stones
39
 
{
40
 
    using namespace world;
41
 
 
42
 
    void Init_simple();
43
 
    void Init_complex();
44
 
 
45
 
 
46
 
/* -------------------- Auxiliary Functions -------------------- */
47
 
 
48
 
    Direction get_push_direction (const StoneContact &sc);
49
 
 
50
 
    /* Move a stone (by sending an impulse) Called when actor hits a
51
 
       stone. */
52
 
    bool maybe_push_stone (const StoneContact &sc);
53
 
 
54
 
/* -------------------- YieldedGridStone -------------------- */
55
 
 
56
 
    // allows to completely remove a Stone and its model
57
 
    // for a short time
58
 
    //
59
 
    // - "delays" animation
60
 
    //
61
 
    // @@@ FIXME: alarms have to be disabled as well
62
 
 
63
 
    class YieldedGridStone {
64
 
        world::Stone   *stone;
65
 
        display::Model *model;
66
 
 
67
 
        YieldedGridStone(const YieldedGridStone&);
68
 
        YieldedGridStone& operator = (const YieldedGridStone&);
69
 
    public:
70
 
 
71
 
        YieldedGridStone(Stone *st);
72
 
        ~YieldedGridStone();
73
 
 
74
 
        void set_stone(enigma::GridPos pos);
75
 
        void dispose();
76
 
    };
77
 
 
78
 
/* -------------------- OnOffStone -------------------- */
79
 
 
80
 
    /*! Base class for all stones that can be on and off.  Understands
81
 
      the messages "on", "off", and "onoff".  Whenever the "on"
82
 
      attribute changes, the object's init_model() method is invoked */
83
 
    class OnOffStone : public Stone {
84
 
    protected:
85
 
        OnOffStone(const char *kind) 
86
 
        : Stone (kind) 
87
 
        { 
88
 
            set_attrib("on", 0.0); 
89
 
        }
90
 
 
91
 
        bool is_on() const { 
92
 
            return int_attrib("on") == 1; 
93
 
        }
94
 
 
95
 
        virtual void set_on(bool newon) {
96
 
            if (newon != is_on()) {
97
 
                set_attrib("on", enigma::Value(newon));
98
 
                init_model();
99
 
                notify_onoff(newon);
100
 
            }
101
 
        }
102
 
 
103
 
        virtual void notify_onoff(bool /*on*/) {}
104
 
 
105
 
        void on_message(const world::Message &msg)
106
 
        {
107
 
            const std::string &m = msg.message;
108
 
            if (m=="onoff")
109
 
                set_on(!is_on());
110
 
            else if (m=="signal")
111
 
                set_on (to_int(msg.value) != 0);
112
 
            else if (m == "on")
113
 
                set_on(true);
114
 
            else if (m=="off")
115
 
                set_on(false);
116
 
        }
117
 
    };
118
 
}
119
 
#endif