Code Search for Developers
 
 
  

mapclient.h from FreePop at Krugle


Show mapclient.h syntax highlighted

/***************************************************************************
                          map.h  -  description
                             -------------------
    begin                : Wed Aug 14 2002
    copyright            : (C) 2002 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 MAPCLIENT_H_INCLUDED
#define MAPCLIENT_H_INCLUDED

#include <map.h>
#include <maptileclient.h>
#include <rotation.h>
#include <ClanLib/network.h>
#include <ClanLib/signals.h>
#include <boost/optional.hpp>
#include <vector>

class WorldPos;
class CL_Point;
class CL_Rect;

/**
 * Contains the world map. Has a list of MapTiles to represent each tile
 * of the map. A point on the map can be lowered/raised in such
 * a way that all adjacent points are also moved to maintain
 * a continuous (hilly or flat) landscape.
 * 
 * The client supports rotating the map to show it from 4 different angles.
 * This is acheived by actually rotating the internal structure. All the methods
 * assume positions that are in terms of the original "server" rotation unless
 * specified otherwise.
 */
class MapClient: public Map {
public:
    /**
     * Constructs a new map of the given dimensions.
     */
    MapClient(int w, int h, CL_NetSession* s);
    
    /**
     * Constructs a map from the input source.
     */
    MapClient(CL_InputSource* i, CL_NetSession* s);
    
    /**
     * Destructor.
     */
    virtual ~MapClient();

    virtual const MapTileClient* getTile(const MapPos& p) const;
    virtual MapTileClient* getTile(const MapPos& p);
    
    virtual const MapTileClient* getTile(const WorldPos& p) const;
    virtual MapTileClient* getTile(const WorldPos& p);

    virtual void raiseTileCornerInt(const MapPos& p, const Corner& c);
    virtual void lowerTileCornerInt(const MapPos& p, const Corner& c);
    
    /**
     * Handle tile raising.
     */
    void onRaiseTileCorner(CL_NetPacket& p, CL_NetComputer &computer);
    
    /**
     * Handle tile lowering.
     */
    void onLowerTileCorner(CL_NetPacket& p, CL_NetComputer &computer);
    
    /**
     * Rotate the whole map and the display 90 degrees clockwise.
     */
    void displayRotateClock();
    
    /**
     * Rotate the whole map and the display 90 degrees anticlockwise.
     */
    void displayRotateAnti();

    /**
     * Get the current display rotation.
     */
    const Rotation& getDisplayRotation() const;

    /**
     * Recalculates the offsets for all the tiles.
     */
    void recalcOffsets();

    /**
     * Refreshes the map view.
     */
    void draw() const;

    /**
     * The tile movement signal. This gets called whenever a tile moves, passing
     * the location of that tile.
     */
    CL_Signal_v1<const MapPos&>& sigTileMoved();
    
    /**
     * Returns the range that this map occupies in terms of display coords.
     */
    CL_Rect calcScreenRange() const;

    /**
     * Find the world coords for a graphical position \p p if the map
     * were completely flat. \p p does not need to be a valid position on the
     * map. No reorientation is performed.
     */
    WorldPos findPosFlatLocal(const CL_Point& p) const;
    
    /**
     * Find the tile at the given graphical position.
     * \return There may not be a corresponding position.
     */
    boost::optional<WorldPos> findPos(const CL_Point& p) const;
    
    /**
     * Find the tile at the given graphical position, without display rotation.
     * \return There may not be a corresponding position.
     */
    boost::optional<WorldPos> findPosLocal(const CL_Point& p) const;

    /**
     * Find the world graphical coords for a world position \p p if the map
     * were completely flat. \p p does not need to be a valid position on the
     * map. No reorientation is performed.
     */
    CL_Point findPosFlatLocal(const WorldPos& p) const;
    
    /**
     * Find the graphic coords of \p p.
     */
    CL_Point findPos(const WorldPos& p) const;
    
    /**
     * Find the graphic coords of \p mtp on tile at \p mp.
     */
    CL_Point findPos(const MapPos& mp, const MapTilePos& mtp) const;
    
    /**
     * Find the graphic coords of \p p, ignoring display rotation.
     */
    CL_Point findPosLocal(const WorldPos& p) const;
    
    /**
     * Find the graphic coords of \p mtp on tile at \p mp, ignoring display
     * rotation.
     */
    CL_Point findPosLocal(const MapPos& mp, const MapTilePos& mtp) const;
    
    /**
     * Rotates a position from the server's orientation to local orientation.
     */
    MapPos localOrient(const MapPos& p) const;
    
    /**
     * Rotates a position from the server's orientation to local orientation.
     */
    MapTilePos localOrient(const MapTilePos& p) const;
    
    /**
     * Rotates a position from the server's orientation to local orientation.
     */
    WorldPos localOrient(const WorldPos& p) const;
    
    /**
     * Rotates a position from the server's orientation to local orientation.
     */
    Corner localOrient(const Corner& p) const;
    
    /**
     * Rotates a position from local orientation to the server's orientation.
     */
    MapPos serverOrient(const MapPos& p) const;
    
    /**
     * Rotates a position from local orientation to the server's orientation.
     */
    MapTilePos serverOrient(const MapTilePos& p) const;
    
    /**
     * Rotates a position from local orientation to the server's orientation.
     */
    WorldPos serverOrient(const WorldPos& p) const;
    
    /**
     * Rotates a position from local orientation to the server's orientation.
     */
    Corner serverOrient(const Corner& p) const;

    virtual bool isValid(const MapPos& p) const;
    virtual bool isValid(const WorldPos& p) const;

    /**
     * Check that \p p is within map bounds, assuming \p p is in local coords.
     */
    bool isValidLocal(const WorldPos& p) const;

    /**
     * If \p p is invalid this returns a pos 1/8th inside the map, and thus
     * valid. Otherwise, returns \p p.
     */
    WorldPos clipLocal(WorldPos p) const;

protected:
    /**
     * Get the tile at the literal location, ignoring display rotation.
     */
    virtual MapTileClient* getTileLocal(const MapPos& p);

    /**
     * Get the tile at the literal location, ignoring display rotation.
     */
    virtual const MapTileClient* getTileLocal(const MapPos& p) const;

private:
    /**
     * The list type.
     */
    typedef std::vector<MapTileClient> TileList;

    /**
     * The MapTiles.
     */
    TileList tiles;

    /**
     * The original un-rotated map width.
     */
    const int origWidth;

    /**
     * The original un-rotated map height.
     */
    const int origHeight;

    /**
     * The display rotation.
     */
    Rotation displayRot;

    /**
     * Slot to receive tile raise messages.
     */
    CL_Slot raiseSlot;

    /**
     * Slot to receive tile lower messages.
     */
    CL_Slot lowerSlot;

    /**
     * Signal to send when a tile moves.
     */
    CL_Signal_v1<const MapPos&> mSigTileMoved;
};

#endif /* ndef MAPCLIENT_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
  client.cpp
  client.h
  clientmisc.cpp
  clientmisc.h
  clientstate.cpp
  clientstate.h
  connectstate.cpp
  connectstate.h
  cropsclient.cpp
  cropsclient.h
  entityclient.cpp
  entityclient.h
  entityclientfactory.cpp
  entityclientfactory.h
  firecolumnclient.cpp
  firecolumnclient.h
  gamestate.cpp
  gamestate.h
  loadstate.cpp
  loadstate.h
  mapclient.cpp
  mapclient.h
  maptileclient.cpp
  maptileclient.h
  messagebox.cpp
  messagebox.h
  oversprite.cpp
  oversprite.h
  paintable.cpp
  paintable.h
  pausefader.cpp
  pausefader.h
  peepclient.cpp
  peepclient.h
  peepmagnetclient.cpp
  peepmagnetclient.h
  playerclient.cpp
  playerclient.h
  playeroptionsdialog.cpp
  playeroptionsdialog.h
  rockclient.cpp
  rockclient.h
  swampclient.cpp
  swampclient.h
  townclient.cpp
  townclient.h
  treeclient.cpp
  treeclient.h
  worldclient.cpp
  worldclient.h