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 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
|
/****************************************************************
**
** Attal : Lords of Doom
**
** genericLord.h
** manages a lord and its units
**
** Version : $Id: genericLord.h,v 1.13 2004/12/05 15:09:43 lusum Exp $
**
** Author(s) : Pascal Audoux
**
** Date : 25/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 GENERICLORD_H
#define GENERICLORD_H
// generic include files
// include files for QT
#include <qptrlist.h>
// application specific include files
#include "libCommon/artefact.h"
#include "libCommon/define.h"
#include "libCommon/skill.h"
#include "libCommon/specialty.h"
#include "libCommon/technic.h"
class QTextStream;
//class GenericArtefact;
class ArtefactManager;
class Creature;
class GenericFightUnit;
class GenericCell;
class GenericPlayer;
class GenericLordModel;
class LordCategoryModel;
enum {
PR_ENEMY = 1,
PR_BASE,
PR_BASEOWNER,
PR_BUILD,
PR_ART,
PR_BONUS,
PR_CHEST,
PR_CREAT,
PR_EXPLORE,
PR_LAST
};
/* ------------------------------
* GenericLord
* ------------------------------ */
LordCharac detectCharac( const QString & type );
QString getCharacName( LordCharac charac );
class GenericLord
{
public:
/** Constructor */
GenericLord();
/// XXX/ Todo !!
/** Destructor */
virtual ~GenericLord();
/** Copy lord */
void copy( GenericLord * );
/** Load lord */
bool load( QTextStream * );
/** Save lord */
void save( QTextStream *, int indent = 0 );
/** Set Id of the lord */
void setId( int id );
/** Return Id of the lord */
int getId() { return _id; }
void reinit();
/** Set owner of the lord */
virtual void setOwner( GenericPlayer * player ) { _player = player; }
/** Get owner of the lord */
GenericPlayer * getOwner() { return _player; }
/** Get name of the lord */
QString getName();
/** Get category name of the lord */
QString getCategoryName();
/** get type of lord */
int getRace();
/** Intializes the lord position*/
virtual void setPosition( GenericCell * cell ) { moveTo( cell ); }
/** Move lord to cell */
virtual void moveTo( GenericCell * cell );
/** Get cell where is the lord */
GenericCell * getCell() { return _currentCell; }
/** Set lord sleeping (or not) */
void setSleeping( bool st ) { _sleeping = st; }
/** Tell if lord is sleeping */
bool isSleeping() { return _sleeping; }
/** Tell if lord is active */
bool isActive() { return true; }
/** Set (or not) a technical book */
void setBook( bool st ) { _hasBook = st; }
/** Tell if the lord has a technical book */
bool isBook() { return _hasBook; }
/** Set unit 'num' */
void setUnit( int num, GenericFightUnit * troop ) { _units[num] = troop; }
/** Return the unit 'num' */
GenericFightUnit * getUnit( int num ) { return _units[num]; }
void setPrio( int num , int value) { _priorities[num] = value; }
/** Return the unit 'num' */
int getPrio( int num ) { return _priorities[num]; }
void clearUnits();
int countUnits();
bool addCreatures( Creature * creature, int number );
ArtefactManager * getArtefactManager() { return _artefactManager; }
/** Compute end of turn */
void endTurn();
/** Collect ressource 'num' */
int collectRessource( int ) { return 0; }
/** Return level of experience of the lord */
int getLevel();
int getCharac( LordCharac type );
int getBaseCharac( LordCharac type );
void setBaseCharac( LordCharac type, int value );
void increaseBaseCharac( LordCharac type, int value );
void decreaseBaseCharac( LordCharac type, int value );
int computeCostMvt( GenericCell * cell );
int computeCostMvt( GenericCell * start, GenericCell * end );
void removeFromGame();
void getOut();
virtual void setVisible( bool state );
bool isVisible() { return _visible; }
/** Adds a new war machine */
void addMachine( int id );
/** \return Returns the number of machines owned */
uint getMachineNumber();
/** \return Return the id of the num-th machine */
uint getMachine( uint num );
/** Removes the num-th machine */
void removeMachine( uint num );
/** Tells if this machine is owned */
bool hasMachine( int id );
/** Tells if this machine type is owned */
bool hasMachineType( int type );
uint computeForceIndicator();
protected:
int _id;
GenericFightUnit * _units[ MAX_UNIT ];
ArtefactManager * _artefactManager;
Specialty _special;
TechnicalBook _book;
Skill _skills[ MAX_SKILL ];
GenericPlayer * _player;
GenericCell * _currentCell;
bool _sleeping;
bool _hasBook, _visible;
int _move, _maxMove;
int _technicPoints, _maxTechnicPoints;
int _morale, _luck;
int _experience;
int _power, _knowledge;
int _attack, _defense;
int _vision;
GenericLordModel * _model;
QPtrList<int> _machines;
int _priorities[PR_LAST+1];
};
/** Model of genericLord */
class GenericLordModel
{
public:
GenericLordModel();
/** Set name of the lord */
void setName( QString name ) { _name = name; }
/** Get name of the lord */
QString getName() { return _name; }
void setCategory( LordCategoryModel * category ) { _category = category; }
LordCategoryModel * getCategory() { return _category; }
/** get race of lord */
uint getRace();
/** Set (or not) a technical book */
void setBook( bool st ) { _hasBook = st; }
/** Tell if the lord has a technical book */
bool isBook() { return _hasBook; }
/** Set unit 'num' */
void setUnit( int num, GenericFightUnit * troop ) { _units[num] = troop; }
/** Return the unit 'num' */
GenericFightUnit * getUnit( int num ) { return _units[num]; }
/** \return Returns level of experience of the lord */
int getLevel() { return 3; }
/** Changes value of the charac 'type' */
void setBaseCharac( LordCharac type, int value );
int getBaseCharac( LordCharac type );
/** Adds a new war machine */
void addMachine( int id );
/** \return Returns the number of machines owned */
uint getMachineNumber();
/** \return Return the id of the num-th machine */
uint getMachine( uint num );
/** Removes the num-th machine */
void removeMachine( uint num );
void save( QTextStream & ts, int indent );
private:
QString _name;
LordCategoryModel * _category;
Specialty _special;
GenericFightUnit * _units[ MAX_UNIT ];
Skill _skills[ MAX_SKILL ];
bool _hasBook;
int _move, _maxMove;
int _technicPoints, _maxTechnicPoints;
int _morale, _luck;
int _experience;
int _power, _knowledge;
int _attack, _defense;
int _knowledgePoints;
int _vision;
QPtrList<int> _machines;
};
/** List of GenericLordModel */
class LordList : public QPtrList<GenericLordModel>
{
public:
/** Constructor */
LordList();
/** Return lord in the list */
GenericLordModel * at( int num ) { return QPtrList<GenericLordModel>::at( num ); }
/** Init list */
bool init();
/** Save on file */
bool save();
};
/** Parser for LordList */
class LordHandler : public QXmlDefaultHandler
{
public:
/** this is the construtor */
LordHandler( LordList * 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, _name;
LordList * _list;
GenericLordModel * _lord;
GenericFightUnit * _unit;
LordCharac _charac;
int _level, _race;
int _type;
int _numUnit, _numLord;
enum State {
StateInit,
StateDocument,
StateLord,
StateName,
StateCharac,
StateUnit,
StateUnitRace,
StateUnitLevel,
StateMachine,
StateNumber
};
State _state;
};
#endif // GENERICLORD_H
|