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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
/****************************************************************
**
** Attal : Lords of Doom
**
** genericBuilding.h
** in order to manage buildings...
**
** Version : $Id: genericBuilding.h,v 1.10 2004/09/12 18:17:24 audoux Exp $
**
** Author(s) : Pascal Audoux
**
** Date : 10/08/2000
**
** Licence :
** 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, 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.
**
****************************************************************/
#ifndef GENERICBUILDING_H
#define GENERICBUILDING_H
// generic include files
// include files for QT
#include <qstring.h>
#include <qptrlist.h>
#include <qxml.h>
// application specific include files
#include "libCommon/action.h"
#include "libCommon/genericMapDisposition.h"
#include "libCommon/log.h"
#include "libCommon/unit.h"
//#include "common/genericLord.h"
class QTextStream;
class GenericPlayer;
class GenericLord;
class GenericCell;
class Condition;
/* ------------------------------
* GenericBuilding
* ------------------------------ */
/** comment for the class */
class GenericBuilding
{
public:
/** Constructor */
GenericBuilding();
/** Destructor */
virtual ~GenericBuilding();
/** Returns return the id of the building */
int getId() { return _id; }
/** Sets the id of this building */
void setId( int id ) { _id = id; }
/** Load building */
virtual bool load( QTextStream * );
/** Save building */
void save( QTextStream * ts, int indent = 0 );
/** \returns Returns the type of the building */
int getType() { return _type; }
/** Stes the type of the building */
virtual void setType( int type ) { _type = type; }
/** Set owner of the building */
virtual void setOwner( GenericPlayer * player ) { _player = player; }
/** Return owner of the building */
GenericPlayer * getOwner() { return _player; }
/** Set type of the building */
int getBuildingType() { return _type; }
/** Return type of the building */
void setBuildingType( int type ) { _type = type; }
/** Enter in the building */
virtual void enter( GenericLord * lord );
/** Exit of the building */
virtual void out( GenericLord * ) {}
/** \return Returns the action list associated to this building */
QPtrList<Action> getActionList( Action::ActionType type );
/** \return Returns the building (model) name */
QString getName();
/** Returns the nb of frame for the animation */
uint getNbFrame();
/** Returns the freq of the animation */
int getAnimFreq();
/** Set position of the building on the map */
virtual void setPosition( GenericCell * cell );
/** Return cell of the map where is the building */
GenericCell * getCell() { return _currentCell; }
/** \return Returns true if this building has already be visited */
bool hasBeenVisited();
/** \return Returns true if the lord has already visited this building */
bool hasBeenVisited( GenericLord * lord );
/** \return Returns the condition for entering in this building */
Condition * getCondition() { return _condition; }
uint getDoorRow();
uint getDoorCol();
GenericMapDisposition::DispositionType getDisposition( uint row, uint col );
protected:
int _id, _type;
GenericPlayer * _player;
GenericCell * _currentCell;
QPtrList<GenericLord> _lords;
Condition * _condition;
};
/** Model of building */
class GenericBuildingModel : public GenericMapDisposition
{
public:
/** Constructor */
GenericBuildingModel();
/** \return Returns the name of the model of building */
QString getName() { return _name; }
/** Sets the name of the model of building */
void setName( QString name ) { _name = name; }
/** \return Returns a description of the building */
QString getDescription() { return _description; }
/** Sets a description of the building */
void setDescription( QString description ) { _description = description; }
/** \return Returns the type of building */
int getType() { return _type; }
/** Sets the type of building */
void setType( int type ) { _type = type; }
/** \return Returns the nb of frames for the animation */
uint getNbFrame() { return _nbFrame; }
/** Sets the nb of frames used for the animation */
void setNbFrame( int nb ) { _nbFrame = nb; }
/** \return Returns the animation frequency */
int getAnimFreq() { return _animFreq; }
/** Sets the animation frequency */
void setAnimFreq( int freq ) { _animFreq = freq; }
/** Add an action associated to this model of building */
void addAction( Action * action ) {
_actionList->append( action );
}
/** \return Returns the list of actions associated to this model */
QPtrList<Action> * getActionList() {
return _actionList;
}
/** Clear the list of actions associated to this model of building */
void clearActions() { _actionList->clear(); }
void save( QTextStream * ts, int indent = 0 );
protected:
QString _name, _description;
QPtrList<Action> * _actionList;
int _type, _nbFrame, _animFreq;
};
/** list of building model */
class BuildingList : public QPtrList<GenericBuildingModel>
{
public:
/** Constructor */
BuildingList();
/** Return base corresponding to 'type' */
GenericBuildingModel * at( int type ) { return QPtrList<GenericBuildingModel>::at( type ); }
/** Init list */
bool init();
/** Save the list (used by theme editor)*/
bool save();
};
/** parser for the building list */
class BuildingHandler : public QXmlDefaultHandler
{
public:
/** Construtor */
BuildingHandler( BuildingList * list );
/** Return the error protocol if parsing failed */
QString errorProtocol() { return _errorProt; }
/** Before starting parsing */
bool startDocument();
/** Define Start elements and associated actions */
bool startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts );
/** Define End elements and associated actions */
bool endElement( const QString& namespaceURI, const QString& localName, const QString& qName );
/** Define what to do of characters */
bool characters( const QString& ch );
/** Error function */
bool fatalError( const QXmlParseException& exception );
private:
QString _errorProt;
BuildingList * _list;
GenericBuildingModel * _building;
Action * _action;
uint _height, _width;
ElementaryAction * _elementary;
enum State {
StateInit,
StateDocument,
StateBuilding,
StateName,
StateDescription,
StateDisposition,
StateFrame,
StateAnim,
StateAction,
StateElementary/*,
StateElementaryArg,
StateElementaryValue*/
};
State _state;
};
#endif // GENERICBUILDING_H
|