File: Level.h

package info (click to toggle)
enigma 1.30%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 76,132 kB
  • sloc: xml: 162,251; cpp: 67,393; ansic: 28,606; makefile: 1,986; sh: 1,298; yacc: 288; perl: 84; sed: 16
file content (482 lines) | stat: -rw-r--r-- 13,683 bytes parent folder | download | duplicates (5)
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
// Copyright 2003 Jeremy Sawicki
//
// This file is part of OxydLib.
//
// OxydLib 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.
//
// OxydLib 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.
//
// You should have received a copy of the GNU General Public License
// along with OxydLib; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#ifndef LEVEL_H
#define LEVEL_H

#include "VecUtils.h"
#include <string>
#include <set>
#include <map>

namespace OxydLib {

// using std::string;
// using std::set;
// using std::map;

enum Language
{
  Language_Invalid = -1,
  Language_First = 0,

  Language_German = Language_First,
  Language_English,
  Language_French,
  Language_International,

  Language_Count,
  Language_Last = Language_Count - 1
};

enum GameMode
{
  GameMode_Invalid = -1,
  GameMode_First = 0,

  GameMode_Hard = GameMode_First,
  GameMode_Easy,

  GameMode_Count,
  GameMode_Last = GameMode_Count - 1
};

enum GridType
{
  GridType_Invalid = -1,
  GridType_First = 0,

  GridType_Surfaces = GridType_First,
  GridType_Pieces,
  GridType_Objects,

  GridType_Count,
  GridType_Last = GridType_Count - 1
};

enum MarbleType
{
  MarbleType_Invalid = -1,
  MarbleType_First = 0,

  MarbleType_Black = MarbleType_First,
  MarbleType_White,
  MarbleType_Meditation,
  MarbleType_Horse,
  MarbleType_Jack,
  MarbleType_LifeSpitter,
  MarbleType_DynamiteHolder,
  MarbleType_Rotor,             /* Oxyd 1 */
  MarbleType_Bug,               /* Oxyd 1 */

  MarbleType_Count,
  MarbleType_Last = MarbleType_Count - 1
};

class Marble
{
public:
  Marble();
  ~Marble();

  MarbleType getMarbleType() const { return m_marbleType; }
  void setMarbleType(MarbleType marbleType) { m_marbleType = marbleType; }

  unsigned int getX() const { return m_x; }
  void setX(unsigned int x) { m_x = x; }

  unsigned int getY() const { return m_y; }
  void setY(unsigned int y) { m_y = y; }

  const std::string &getData(GameMode gameMode) const { return m_data[gameMode]; }
  std::string *getDataForWrite(GameMode gameMode) { return &m_data[gameMode]; }

private:
  MarbleType m_marbleType;
  unsigned int m_x;
  unsigned int m_y;
  std::string m_data[GameMode_Count];
};

class RubberBand
{
public:
  RubberBand();
  ~RubberBand();

  int getNaturalLength() const { return m_naturalLength; }
  void setNaturalLength(int naturalLength) { m_naturalLength = naturalLength; }

  int getForce() const { return m_force; }
  void setForce(int force) { m_force = force; }

  int getFirstEndMarble() const { return m_firstEndMarble; }
  void setFirstEndMarble(int nMarble) { m_firstEndMarble = nMarble; }

  bool isSecondEndMarble() const { return m_bSecondEndIsMarble; }
  int getSecondEndMarble() const { return m_secondEndMarble; }
  void setSecondEndMarble(int nMarble);
  unsigned int getSecondEndPieceX() const { return m_secondEndPieceX; }
  unsigned int getSecondEndPieceY() const { return m_secondEndPieceY; }
  void setSecondEndPiece(unsigned int x, unsigned int y);

  bool operator == (const RubberBand &other) const;
  bool operator != (const RubberBand &other) const;

private:
  int m_naturalLength;
  int m_force;
  int m_firstEndMarble;
  bool m_bSecondEndIsMarble;
  int m_secondEndMarble;
  unsigned int m_secondEndPieceX;
  unsigned int m_secondEndPieceY;
};

class Block
{
public:
  Block();
  Block(unsigned int x, unsigned int y);
  ~Block();

  unsigned int getX() const { return m_x; }
  void setX(unsigned int x) { m_x = x; }

  unsigned int getY() const { return m_y; }
  void setY(unsigned int y) { m_y = y; }

  bool operator < (const Block &other) const;
  bool operator == (const Block &other) const;
  bool operator != (const Block &other) const;

private:
  unsigned int m_x;
  unsigned int m_y;
};

enum Direction
{
  Direction_Invalid = -1,
  Direction_First = 0,

  Direction_Up = Direction_First,
  Direction_Down,
  Direction_Left,
  Direction_Right,

  Direction_Count,
  Direction_Last = Direction_Count - 1
};

class ScrambleItem
{
public:
  ScrambleItem();
  ScrambleItem(unsigned int x, unsigned int y, Direction dir);
  ~ScrambleItem();

  unsigned int getX() const { return m_x; }
  void setX(unsigned int x) { m_x = x; }

  unsigned int getY() const { return m_y; }
  void setY(unsigned int y) { m_y = y; }

  Direction getDir() const { return m_dir; }
  void setDir(Direction dir) { m_dir = dir; }

private:
  unsigned int m_x;
  unsigned int m_y;
  Direction m_dir;
};

class Laser
{
public:
  Laser();
  Laser(Direction dir, bool bOn);
  ~Laser();

  Direction getDir() const { return m_dir; }
  void setDir(Direction dir) { m_dir = dir; }

  bool getOn() const { return m_bOn; }
  void setOn(bool bOn) { m_bOn = bOn; }

  bool operator == (const Laser &other) const;
  bool operator != (const Laser &other) const;

private:
  Direction m_dir;
  bool m_bOn;
};

class Oscillator
{
public:
  Oscillator();
  Oscillator(unsigned int period, bool bOn);
  ~Oscillator();

  unsigned int getPeriod() const { return m_period; }
  void setPeriod(unsigned int period) { m_period = period; }

  bool getOn() const { return m_bOn; }
  void setOn(bool bOn) { m_bOn = bOn; }

  bool operator == (const Oscillator &other) const;
  bool operator != (const Oscillator &other) const;

private:
  unsigned int m_period;
  bool m_bOn;
};

typedef std::map<Block, Oscillator> OscillatorMap;

class SignalLocation
{
public:
  SignalLocation();
  SignalLocation(unsigned int x, unsigned int y, GridType gridType);
  ~SignalLocation();

  unsigned int getX() const { return m_x; }
  void setX(unsigned int x) { m_x = x; }

  unsigned int getY() const { return m_y; }
  void setY(unsigned int y) { m_y = y; }

  GridType getGridType() const { return m_gridType; }
  void setGridType(GridType gridType) { m_gridType = gridType; }

  bool operator < (const SignalLocation &other) const;
  bool operator == (const SignalLocation &other) const;
  bool operator != (const SignalLocation &other) const
  { return !(*this == other); }

private:
  unsigned int m_x;
  unsigned int m_y;
  GridType m_gridType;
};

class Grid
{
public:
  Grid();
  Grid(int width, int height);
  ~Grid();

  unsigned int getWidth() const { return m_width; }
  unsigned int getHeight() const { return m_height; }

private:
  friend class Level;
  void resize(unsigned int width, unsigned int height);

public:
  unsigned char get(unsigned int x, unsigned int y) const;
  void set(unsigned int x, unsigned int y, unsigned char val);

private:
  unsigned int m_width;
  unsigned int m_height;
  ByteVec m_data;
};

class Level
{
public:
  Level();
  ~Level();

  void clear();

  bool getInit() const { return m_bInit; }
  void setInit(bool bInit) { m_bInit = bInit; }

  bool isEmpty() const { return m_bEmpty; }
  void setEmpty(bool bEmpty) { m_bEmpty = bEmpty; }

  unsigned int getWidth() const { return m_width; }
  unsigned int getHeight() const { return m_height; }
  void resize(unsigned int width, unsigned int height);

  bool getMeditation() const { return m_bMeditation; }
  void setMeditation(bool bMeditation) { m_bMeditation = bMeditation; }

  bool getHarmlessMeditationMarbles() const
  { return m_bHarmlessMeditationMarbles; }
  void setHarmlessMeditationMarbles(bool bHarmlessMeditationMarbles)
  { m_bHarmlessMeditationMarbles = bHarmlessMeditationMarbles; }

  size_t getNumMarbles() const { return m_marbles.size(); }
  void setNumMarbles(int num) { m_marbles.resize(num); }
  const Marble &getMarble(int nMarble) const { return m_marbles[nMarble]; }
  Marble *getMarbleForWrite(int nMarble) { return &m_marbles[nMarble]; }

  int getNumRubberBands(GameMode gameMode) const;
  const RubberBand &getRubberBand(GameMode gameMode, int nRubberBand) const;
  RubberBand *getRubberBandForWrite(GameMode gameMode, int nRubberBand);
  void addRubberBand(GameMode gameMode,
                     const RubberBand &rubberBand,
                     int nRubberBand = -1);
  void removeRubberBand(GameMode gameMode, int nRubberBand);

  int getBlackRubberBandPieceNaturalLength(GameMode gameMode) const;
  void setBlackRubberBandPieceNaturalLength(GameMode gameMode,
                                            int naturalLength);

  int getBlackRubberBandPieceForce(GameMode gameMode) const;
  void setBlackRubberBandPieceForce(GameMode gameMode, int force);

  int getWhiteRubberBandPieceNaturalLength(GameMode gameMode) const;
  void setWhiteRubberBandPieceNaturalLength(GameMode gameMode,
                                            int naturalLength);

  int getWhiteRubberBandPieceForce(GameMode gameMode) const;
  void setWhiteRubberBandPieceForce(GameMode gameMode, int force);

  int getRubberBandObjectNaturalLength(GameMode gameMode) const;
  void setRubberBandObjectNaturalLength(GameMode gameMode, int naturalLength);

  int getRubberBandObjectForce(GameMode gameMode) const;
  void setRubberBandObjectForce(GameMode gameMode, int force);

  int getBlackRubberBandObjectMarble() const;
  void setBlackRubberBandObjectMarble(int nMarble);

  int getWhiteRubberBandObjectMarble() const;
  void setWhiteRubberBandObjectMarble(int nMarble);

  bool getRequireMagicPiece() const
  { return m_bRequireMagicPiece; }
  void setRequireMagicPiece(bool bRequireMagicPiece)
  { m_bRequireMagicPiece = bRequireMagicPiece; }

  bool getScrolling() const { return m_bScrolling; }
  void setScrolling(bool bScrolling) { m_bScrolling = bScrolling; }

  bool getReset(GameMode gameMode) const
  { return m_bReset[gameMode]; }
  void setReset(GameMode gameMode, bool bReset)
  { m_bReset[gameMode] = bReset; }

  bool getWalkThroughPuzzle() const
  { return m_bWalkThroughPuzzle; }
  void setWalkThroughPuzzle(bool bWalkThroughPuzzle)
  { m_bWalkThroughPuzzle = bWalkThroughPuzzle; }

  int getFlatForce(GameMode gameMode) const
  { return m_flatForce[gameMode]; }
  void setFlatForce(GameMode gameMode, int flatForce)
  { m_flatForce[gameMode] = flatForce; }

  int getSlopeForce(GameMode gameMode) const
  { return m_slopeForce[gameMode]; }
  void setSlopeForce(GameMode gameMode, int slopeForce)
  { m_slopeForce[gameMode] = slopeForce; }

  int getFriction(GameMode gameMode) const
  { return m_friction[gameMode]; }
  void setFriction(GameMode gameMode, int friction)
  { m_friction[gameMode] = friction; }

  int getNumScrambleItems() const;
  const ScrambleItem &getScrambleItem(int nScrambleItem) const;
  ScrambleItem *getScrambleItemForWrite(int nScrambleItem);
  void addScrambleItem(const ScrambleItem &scrambleItem,
                       int nScrambleItem = -1);
  void removeScrambleItem(int nScrambleItem);

  const Laser &getLaser(int nLaser) const;
  void setLaser(int nLaser, const Laser &laser);

  const OscillatorMap &getOscillators(GameMode gameMode) const;
  OscillatorMap *getOscillatorsForWrite(GameMode gameMode);

  const std::string &getNoteText(int nNote, Language lang) const;
  void setNoteText(int nNote, Language lang, const std::string &noteText);

  const Grid &getGrid(GridType gridType) const { return m_grids[gridType]; }
  Grid *getGridForWrite(GridType gridType) { return &m_grids[gridType]; }

  const std::vector<std::string> &getSpecialItems() const { return m_specialItems; }
  std::vector<std::string> *getSpecialItemsForWrite() { return &m_specialItems; }

  void getSenders(std::set<SignalLocation> *pSenders) const;
  int getNumRecipients(const SignalLocation &sender) const;
  const SignalLocation &getRecipient(const SignalLocation &sender,
                                     int nRecipient) const;
  void setRecipient(const SignalLocation &sender,
                    int nRecipient,
                    const SignalLocation &recipient);
  void addRecipient(const SignalLocation &sender,
                    const SignalLocation &recipient,
                    int nRecipient = -1);
  void removeRecipient(const SignalLocation &sender,
                       int nRecipient);

private:
  bool m_bInit;
  bool m_bEmpty;

  unsigned int m_width;
  unsigned int m_height;

  bool m_bMeditation;
  bool m_bHarmlessMeditationMarbles;
  std::vector<Marble> m_marbles;
  std::vector<RubberBand> m_rubberBands[GameMode_Count];
  int m_blackRubberBandPieceNaturalLength[GameMode_Count];
  int m_blackRubberBandPieceForce[GameMode_Count];
  int m_whiteRubberBandPieceNaturalLength[GameMode_Count];
  int m_whiteRubberBandPieceForce[GameMode_Count];
  int m_rubberBandObjectNaturalLength[GameMode_Count];
  int m_rubberBandObjectForce[GameMode_Count];
  int m_blackRubberBandObjectMarble;
  int m_whiteRubberBandObjectMarble;
  bool m_bRequireMagicPiece;
  bool m_bScrolling;
  bool m_bReset[GameMode_Count];
  bool m_bWalkThroughPuzzle;
  int m_flatForce[GameMode_Count];
  int m_slopeForce[GameMode_Count];
  int m_friction[GameMode_Count];
  std::vector<ScrambleItem> m_scrambleItems;
  Laser m_lasers[3];
  OscillatorMap m_oscillators[GameMode_Count];
  std::string m_noteText[2][Language_Count];

  Grid m_grids[GridType_Count];

  std::vector<std::string> m_specialItems;

  typedef std::map<SignalLocation, std::vector<SignalLocation> > SignalMap;
  SignalMap m_signals;
};

bool parseNumberList(const std::string &str, std::vector<int> *pNumberList);
bool parseLevel(const ByteVec &in, Level *pLevel, std::string *pMsg = 0);
bool unparseLevel(const Level &level, ByteVec *pOut, std::string *pMsg = 0);

}

#endif