Code Search for Developers
 
 
  

rules.h from FreePop at Krugle


Show rules.h syntax highlighted

/***************************************************************************
                           rules.h
                           -------------------
    begin                : Sun Jul 18 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 RULES_H_INCLUDED
#define RULES_H_INCLUDED

#include <misc.h>

#include <ClanLib/network.h>

#include <boost/lexical_cast.hpp>

#include <map>
#include <string>
 
/**
 * Class holds common game rules. These are all the configurable options for a
 * server, including game options and parameters, and any server-specific
 * things. The client will get a copy of all of them. A client shouldn't try to
 * modify them - there is no way the server would notice.
 */
class Rules {
public:
    /**
     * A rule is missing.
     */
    class Missing: public std::runtime_error {
    public:
        /**
         * Constructor.
         */
        Missing(const std::string& key);
        
        /**
         * Destructor.
         */
        ~Missing() throw();
    };
    
    /**
     * A rule cannot be parsed, it has bad formatting.
     */
    class Corrupt: public std::runtime_error {
    public:
        /**
         * Constructor.
         */
        Corrupt(const std::string& key);
                
        /**
         * Destructor.
         */
        ~Corrupt() throw();
    };
    
    /**
     * A rule is not within the allowed range.
     */
    class Bad: public std::runtime_error {
    public:
        /**
         * Constructor.
         */
        Bad(const std::string& key, const std::string& range);
                
        /**
         * Destructor.
         */
        ~Bad() throw();
    };

    /**
     * Map type for console variables.
     */
    typedef std::map<std::string, std::string> VarMap;

public:
    /**
     * Constructor. Server side.
     */
    Rules(const VarMap& vars);
    
    /**
     * Constructor. Client side.
     */
    Rules(CL_InputSource& is);
    
    /**
     * Destructor.
     */
    ~Rules();
    
    /**
     * Inject the rules into an output source.
     */
    void inject(CL_OutputSource& os) const;
    
    /**
     * Get a bunch of helpful stuff.
     */
    static std::string help();
    
    /**
     * Map width.
     */
    unsigned int width;
    
    /**
     * Map height.
     */
    unsigned int height;
    
    /**
     * Map gerenator type.
     */
    unsigned int generator;

    /**
     * The map theater type.
     */
    std::string theater;
    
    /**
     * Time (ms) until a firecolumn dies.
     */
    unsigned int firecolumn_lifetime;
    
    /**
     * The rate (ms per strength point) at which a tree burns.
     */
    unsigned int tree_burnrate;
    
    /**
     * The range a flame can propogate and be caught by a tree.
     */
    float tree_flamerange;
    
    /**
     * The duration a tree must be within range to catch fire.
     */
    unsigned int tree_flameduration;
    
    /**
     * The duration to go from dead to decay and be removed.
     */
    unsigned int tree_decayduration;
    
    /**
     * The rate (ms per strength point) at which a peep burns.
     */
    unsigned int peep_burnrate;
    
    /**
     * The range a flame can propogate and be caught by a peep.
     */
    float peep_flamerange;
    
    /**
     * The duration a peep must be within range to catch fire.
     */
    unsigned int peep_flameduration;
    
    /**
     * The rate (ms per strength point) at which a peep dies from exposure
     * while walking.
     */
    unsigned int peep_exhaustrate;
    
    /**
     * The speed (ms per tile unit) at which a peep walks.
     */
    unsigned int peep_walkspeed;
    
    /**
     * The rate (ms per strength point) at which a town burns.
     */
    unsigned int town_burnrate;
    
    /**
     * The range a flame can propogate and be caught by a town.
     */
    float town_flamerange;
    
    /**
     * The rate at which a town grows. Higher = slower.
     * 1000 ~ more than double every second.
     */
    unsigned int town_growrate;

    /**
     * The strength at which a town will spawn a peep.
     */
    float town_maxstrength;

    /**
     * The strength of the peep a town spawns.
     */
    float town_spawnstrength;
    
    /**
     * The range a swamp can catch a peep.
     */
    float swamp_range;

private:    
    /**
     * Lookup something from a map, throw if not found.
     */
    static std::string lookup(const VarMap& map, const std::string& key);
    
    /**
     * Acts just like boost::lexical_cast except that it reformats
     * boost::bad_lexical_cast into BadCastError.
     */
    template <typename T> static T lexical_cast(const std::string& k,
        const std::string& v) {
        try {
            return boost::lexical_cast<T>(v);
        } catch (boost::bad_lexical_cast &e) {
            throw Corrupt(k);
        }
    }
    
    /**
     * Look it up and lexical_cast it.
     */
    template <typename T> static void parse(T* t, const VarMap& map,
        const std::string& k) {
        *t = lexical_cast<T>(k, lookup(map, k));
    }
    
    /**
     * If range is false, throws Bad.
     */
    static void check(bool range, const std::string& r, const std::string& k);
};

#endif /* ndef RULES_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

  client/
    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
  server/
    Makefile.am
    contagion.cpp
    contagion.h
  Makefile.am
  common.cpp
  common.h
  corner.cpp
  corner.h
  crops.cpp
  crops.h
  entity.cpp
  entity.h
  entityfactory.cpp
  entityfactory.h
  firecolumn.cpp
  firecolumn.h
  gridmap.h
  identity.cpp
  identity.h
  map.cpp
  map.h
  mappos.cpp
  mappos.h
  maptile.cpp
  maptile.h
  maptilepos.cpp
  maptilepos.h
  misc.h
  peep.cpp
  peep.h
  peepmagnet.cpp
  peepmagnet.h
  player.cpp
  player.h
  rock.cpp
  rock.h
  rotation.cpp
  rotation.h
  rules.cpp
  rules.h
  slope.cpp
  slope.h
  swamp.cpp
  swamp.h
  tempo.cpp
  tempo.h
  town.cpp
  town.h
  tree.cpp
  tree.h
  worldpos.cpp
  worldpos.h