File: BaseWorld.h

package info (click to toggle)
cyphesis-cpp 0.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,752 kB
  • sloc: cpp: 94,194; xml: 40,196; python: 8,717; sh: 4,164; makefile: 1,968; ansic: 753
file content (166 lines) | stat: -rw-r--r-- 5,774 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2000-2004 Alistair Riddoch
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


#ifndef COMMON_BASE_WORLD_H
#define COMMON_BASE_WORLD_H

#include "globals.h"

#include <Atlas/Message/Element.h>
#include <Atlas/Objects/ObjectsFwd.h>

#include <sigc++/signal.h>

class ArithmeticScript;
class LocatedEntity;
class SystemTime;
class Task;

typedef std::map<long, LocatedEntity *> EntityDict;

/// \brief Base class for game world manager object.
///
/// This base class provides the common features required by cyphesis
/// for the object which encapsulates the game world. Other classes
/// inherit from this provide the core game world system.
class BaseWorld {
  private:
    /// \brief Copy constructor deleted to prevent slicing
    BaseWorld(const BaseWorld &) = delete;
    /// \brief Assignment operator deleted to prevent slicing
    const BaseWorld & operator=(const BaseWorld &) = delete;

    /// \brief Singleton instance pointer for the World manager object.
    static BaseWorld * m_instance;
  protected:
    /// \brief The in-game time in seconds.
    ///
    /// Calculated from the out-of-game time by applying an offset stored
    /// at startup
    double m_realTime;

    /// \brief Dictionary of all the objects in the world.
    ///
    /// Pointers to all in-game entities in the world are stored keyed to
    /// their integer ID.
    EntityDict m_eobjects;

    /// \brief Whether the base world is suspended or not.
    ///
    /// If this is set to true, the world is "suspended". In this state no
    /// Tick ops are sent.
    /// This is useful for when a world author wants to edit the world
    /// without the simulation altering it.
    bool m_isSuspended;

    explicit BaseWorld(LocatedEntity &);

    /// \brief Called when the world is resumed.
    virtual void resumeWorld() {}

  public:
    /// \brief The top level in-game entity in the world.
    LocatedEntity & m_gameWorld;

    virtual ~BaseWorld();

    /// \brief Singleton accessor for the World manager object.
    static BaseWorld & instance() {
        return *m_instance;
    }

    LocatedEntity * getEntity(const std::string & id) const;

    LocatedEntity * getEntity(long id) const;

    /// \brief Read only accessor for the in-game objects dictionary.
    const EntityDict & getEntities() const {
        return m_eobjects;
    }

    /// \brief Read only accessor for the in-game time.
    const double & getTime() const {
        return m_realTime;
    }

    /// \brief Get the time the world has been running since the server started.
    const double upTime() const {
        return m_realTime - timeoffset;
    }

    /// \brief Gets whether the world is suspended or not.
    const bool & getIsSuspended() const {
    	return m_isSuspended;
    }

    /// \brief Sets whether the world is suspended or not.
    /// If this is set to true, the world is "suspended". In this state no
    /// Tick ops are sent.
    /// This is useful for when a world author wants to edit the world
    /// without the simulation altering it.
    void setIsSuspended(bool suspended);

    /// \brief Main world loop function.
    virtual bool idle(const SystemTime &) = 0;

    /// \brief Add a new entity to the world.
    virtual LocatedEntity * addEntity(LocatedEntity * obj) = 0;

    /// \brief Create a new entity and add to the world.
    virtual LocatedEntity * addNewEntity(const std::string & type,
                                  const Atlas::Objects::Entity::RootEntity &) = 0;

    virtual int createSpawnPoint(const Atlas::Message::MapType & data,
                                 LocatedEntity * ent) = 0;

    virtual int getSpawnList(Atlas::Message::ListType & data) = 0;

    virtual LocatedEntity * spawnNewEntity(
          const std::string & name,
          const std::string & type,
          const Atlas::Objects::Entity::RootEntity &) = 0;

    /// \brief Create a new task
    virtual Task * newTask(const std::string &, LocatedEntity &) = 0;

    /// \brief Activate a new tast
    virtual Task * activateTask(const std::string &, const std::string &,
                                LocatedEntity *, LocatedEntity &) = 0;

    /// \brief Create a new Arithmetic object
    virtual ArithmeticScript * newArithmetic(const std::string &,
                                             LocatedEntity *) = 0;

    /// \brief Pass an operation to the world.
    virtual void message(const Atlas::Objects::Operation::RootOperation &,
                         LocatedEntity & obj) = 0;

    /// \brief Find an entity of the given name.
    virtual LocatedEntity * findByName(const std::string & name) = 0;

    /// \brief Find an entity of the given type.
    virtual LocatedEntity * findByType(const std::string & type) = 0;

    /// \brief Add an entity provided to the list of perceptive entities.
    virtual void addPerceptive(LocatedEntity *) = 0;

    /// \brief Signal that an operation is being dispatched.
    sigc::signal<void, Atlas::Objects::Operation::RootOperation> Dispatching;
};

#endif // COMMON_BASE_WORLD_H