File: parser.h

package info (click to toggle)
attal 0.9.2-1.2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,992 kB
  • ctags: 5,972
  • sloc: cpp: 44,510; sh: 160; makefile: 45
file content (249 lines) | stat: -rw-r--r-- 6,064 bytes parent folder | download | duplicates (2)
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
/****************************************************************
**
** Attal : Lords of Doom
**
** parser.h
** Parser for scenarii and saved games.
**
** Version : $Id: parser.h,v 1.15 2004/12/04 14:26:57 lusum Exp $
**
** Author(s) : Pascal Audoux - Sardi Carlo
**
** Date : 04/02/2001
**
** 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 PARSER_H
#define PARSER_H

 
// generic include files
// include files for QT
#include <qptrstack.h>
#include <qtextstream.h>
#include <qvaluelist.h>
#include <qxml.h>
// application specific include files
#include "libCommon/genericLord.h"
#include "libCommon/quest.h"
 
/*              ------------------------------
 *                         ScenarioParser
 *              ------------------------------ */

class GameData;
class GenericArtefact;
class GenericBase;
class GenericBonus;
class GenericBuilding;
class GenericChest;
class GenericEvent;
class GenericFightUnit;
class GenericLord;
class GenericMapCreature;

/** comment for the class */
class ScenarioParser : public QXmlDefaultHandler
{
public:
	/** Constructor */
	ScenarioParser( GameData * data );
	
	/** 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 );
	
	bool startElementLord( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts );
	
	bool startElementBase( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts );

	bool startElementQuest( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts );

	bool startElementEvent( 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 );

	bool endElementLord( const QString& namespaceURI, const QString& localName, const QString& qName );
	
	bool endElementBase( const QString& namespaceURI, const QString& localName, const QString& qName );

	bool endElementQuest( const QString& namespaceURI, const QString& localName, const QString& qName );

	bool endElementEvent( const QString& namespaceURI, const QString& localName, const QString& qName );
	
	/** Define what to do of characters */
	bool characters( const QString& ch );
	
	bool charactersLord( const QString& ch );
	
	bool charactersBase( const QString& ch );

	bool charactersQuest( const QString& ch );

	bool charactersEvent( const QString& ch );

	/** Error function */
	bool fatalError( const QXmlParseException& exception );

protected:
	void manageCondition( const QString & type );

	void manageConditionParam( const QString & param );

private:
	GameData * _data;
 	QTextStream * _tempStream;
	QByteArray * _buffer;
	QString _errorProt;
	GenericBase * _base;
	GenericBuilding * _building;
	GenericLord * _lord;
	GenericMapCreature * _creature;
	Quest * _quest;
	GenericFightUnit * _unit;
	GenericEvent * _event;
	GenericArtefact * _artefact;
	GenericLordArtefact * _lordArtefact;
	QuestCondition * _currentCondition;
	QPtrStack<QuestConditionComposite> _conditionStack;
	QValueList<uint> _params;
	LordCharac _charac;
	int _height, _width;
	int _id, _row, _col, _pos, _baseType;
	int _number, _move, _health;
	int _behaviour;
	bool _flee, _looking;
	int _race, _level, _res;
	int _machine;
	QString _type, _baseName;
	int _player;
	bool _posOk;
	uint _nbParam;

	enum State {
		StateInit,
		StateDocument,
		StateName,
		StateTheme,
		StateDescription,
		StateMap,
		StateWidth,
		StateHeight,
		StateBase,
		StateCreature,
		StateCreatureCol,
		StateCreatureRow,
		StateCreatureRace,
		StateCreatureLevel,
		StateCreatureStack,
		StateCreatureBehaviour,
		StateCreatureGrowth,
		StateCreatureGrowthParam,
		StateCreatureFlee,
		StateCreatureLooking,
		StateBuilding,
		StateBuildingCol,
		StateBuildingRow,
		StateLord,
		StateEvent,
		StateQuest,
		StatePlayer,
		StatePlayerName,
		StatePlayerRuled,
		StatePlayerBase,
		StatePlayerBuilding,
		StatePlayerLord,
		StatePlayerResource
	};

	enum LordState {
		LordStateInit,
		LordStateCol,
		LordStateRow,
		LordStateCharac,
		LordStateUnit,
		LordStateUnitRace,
		LordStateUnitLevel,
		LordStateUnitNumber,
		LordStateUnitMove,
		LordStateUnitHealth,
		LordStateArtefact,
		LordStateArtefactPosition,
		LordStateMachine
	};

	enum BaseState {
		BaseStateInit,
		BaseStateType,
		BaseStateName,
		BaseStateBuilding,
		BaseStateForbidden,
		BaseStateCol,
		BaseStateRow,
		BaseStateUnit,
		BaseStateUnitRace,
		BaseStateUnitLevel,
		BaseStateUnitNumber,
		BaseStateUnitMove,
		BaseStateUnitHealth,
	};

	enum QuestState {
		QuestInit,
		QuestQuest,
		QuestName,
		QuestConfirmation,
		QuestDescription,
		QuestStart,
		QuestFail,
		QuestSuccess,
		QuestStartEndMessage,
		QuestStartAgree,
		QuestStartDisagree,
		QuestStartEndArg,
		QuestDefCondition,
		QuestConditionParam,
		QuestAction,
		QuestMessage
	};

	enum EventState {
		EventInit,
		EventRow,
		EventCol,
		EventArtefact,
		EventBonus,
		EventBonusParam,
		EventChest,
		EventChestParam
	};

	State _state;
	LordState _lordState;
	BaseState _baseState;
	QuestState _questState, _oldQuestState;
	EventState _eventState;



};

#endif // PARSER_H