Code Search for Developers
 
 
  

entityserver.h from FreePop at Krugle


Show entityserver.h syntax highlighted

/***************************************************************************
                           entityserver.h
                           -------------------
    begin                : Wed May 12 2004
    copyright            : (C) 2004 by Brendon Higgins
    email                : freepop-devel@lists.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef ENTITYSERVER_H_INCLUDED
#define ENTITYSERVER_H_INCLUDED

#include <identity.h>
#include <boost/optional.hpp>
#include <ClanLib/network.h>

class WorldPos;
class WorldServer;
class PlayerServer;    

/**
 * An entity, server edition.
 */
class EntityServer {
protected:
    /**
     * This object's identity.
     */
    Identity id;

public:
    /**
     * The priority of some thing that occupies a tile.
     */
    enum OccupyRank {
        /**
         * Easily removed.
         */
        NONE,

        /**
         * Trees, shrubs, general world foliage. Easily removed by most.
         */
        TREE,

        /**
         * Towns and crops. Can be removed by effects.
         */
        TOWN,

        /**
         * Swamps, fungus, and fonts.
         */
        SWAMP,

        /**
         * Rocks.
         */
        ROCK,

        /**
         * Earthquake entities.
         */
        QUAKE,

        /**
         * Maximum rank. Nothing can remove an entity with this rank.
         */
        MAX
    };

    /**
     * Constructor.
     */
    EntityServer();

    /**
     * Destructor.
     * \note This may not be called immediately after the object is removed
     * from the world's primary list. If you want something to happen as soon
     * as an entity is removed from the map then override removed().
     */
    virtual ~EntityServer();

    /**
     * Called just after the entity is added to the map. Defaults to no-op.
     */
    virtual void added(WorldServer* w, int reason);

    /**
     * Called just before entity is removed from the world. Defaults to no-op.
     */
    virtual void removed(WorldServer* w, int reason);

    /**
     * Get the entitys position.
     */
    virtual WorldPos getPos() const = 0;

    /**
     * Get an identifier to this Entity.
     */
    const Identity& getIdentity() const;

    /**
     * Do some entity logic.
     * If the entity must be destroyed, this returns the reason in the
     * optional, otherwise it returns nothing in the optional.
     * \param w The world.
     * \param d The delay since last update (ms).
     */
    virtual boost::optional<int> update(WorldServer* w, unsigned int d) = 0;

    /**
     * Send a complete create packet to \p g.
     */
    void sendCreate(const WorldServer* s, CL_NetGroup& g, int reason) const;

    /**
     * Send a complete update of this entity to all in \p g.
     */
    void sendFullUpdate(const WorldServer* s, CL_NetGroup& g) const;

    /**
     * Return the type of entity this is, according to those in EntityFactory.
     */
    virtual int getType() const = 0;
    
    /**
     * Return the occupation rank. Higher rankings have priority over lower.
     * \note The default is 0 (easily removed).
     */
    virtual OccupyRank getOccupyRank() const;

    /**
     * Return the slot of the owner player. Many entities aren't owned, so they
     * must return 0, and this is the default.
     */
    virtual const PlayerServer* getOwner() const;
    
    /**
     * Return the slot of the owner player. Many entities aren't owned, so they
     * must return 0, and this is the default.
     */
    virtual PlayerServer* getOwner();
    
    /**
     * Inject complete status info into \p os.
     */
    virtual void inject(CL_OutputSource& os) const = 0;
    
    /**
     * Remove this entity from all given clients.
     */
    void destroy(const WorldServer* s, CL_NetGroup& g, int reason);
};

#endif /* ndef ENTITYSERVER_H_INCLUDED */




See more files for this project here

FreePop

FreePop is a multi-platform tile-based game based on the great old game Populous 2 by Bullfrog Productions Ltd., but much improved.

Project homepage: http://sourceforge.net/projects/freepop
Programming language(s): C++
License: other

  Makefile.am
  contagion.cpp
  contagion.h
  cropsserver.cpp
  cropsserver.h
  entityserver.cpp
  entityserver.h
  firecolumnserver.cpp
  firecolumnserver.h
  mapserver.cpp
  mapserver.h
  maptileserver.cpp
  maptileserver.h
  peepmagnetserver.cpp
  peepmagnetserver.h
  peepserver.cpp
  peepserver.h
  playerserver.cpp
  playerserver.h
  prone.cpp
  prone.h
  rockserver.cpp
  rockserver.h
  server.cpp
  server.h
  swampserver.cpp
  swampserver.h
  townserver.cpp
  townserver.h
  trap.cpp
  trap.h
  trapable.cpp
  trapable.h
  treeserver.cpp
  treeserver.h
  worldserver.cpp
  worldserver.h