File: grammar.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (770 lines) | stat: -rw-r--r-- 14,640 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
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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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 3 of the License, 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef HYPNO_GRAMMAR_H
#define HYPNO_GRAMMAR_H

#include "common/array.h"
#include "common/hash-ptr.h"
#include "common/hash-str.h"
#include "common/list.h"
#include "common/queue.h"
#include "common/rect.h"
#include "common/str.h"

#include "video/smk_decoder.h"

namespace Hypno {

typedef Common::String Filename;
typedef Common::List<Filename> Filenames;

class HypnoSmackerDecoder : public Video::SmackerDecoder {
public:
	bool loadStream(Common::SeekableReadStream *stream) override;

protected:
	uint32 getSignatureVersion(uint32 signature) const override;
};

class MVideo {
public:
	MVideo(Filename, Common::Point, bool, bool, bool);
	Filename path;
	Common::Point position;
	bool scaled;
	bool transparent;
	bool loop;
	HypnoSmackerDecoder *decoder;
};

typedef Common::Array<MVideo> Videos;

enum HotspotType {
	MakeMenu,
	MakeHotspot
};

enum ActionType {
	MiceAction,
	TimerAction,
	PaletteAction,
	BackgroundAction,
	HighlightAction,
	OverlayAction,
	EscapeAction,
	SaveAction,
	LoadAction,
	LoadCheckpointAction,
	QuitAction,
	CutsceneAction,
	PlayAction,
	IntroAction,
	AmbientAction,
	WalNAction,
	GlobalAction,
	TalkAction,
	SwapPointerAction,
	SoundAction,
	ChangeLevelAction
};

class Action {
public:
	virtual ~Action() {} // needed to make Action polymorphic
	ActionType type;
};

typedef Common::Array<Action *> Actions;

class Hotspot;

typedef Common::Array<Hotspot> Hotspots;
typedef Common::Array<Hotspots *> HotspotsStack;
typedef Common::Array<Graphics::Surface *> Frames;

class Hotspot {
public:
	Hotspot(HotspotType type_, Common::Rect rect_ = Common::Rect(0, 0, 0, 0)) {
		type = type_;
		rect = rect_;
		smenu = nullptr;
	}
	HotspotType type;
	Common::String flags[3];
	Common::Rect rect;
	Common::String setting;
	Filename background;
	Frames backgroundFrames;
	Actions actions;
	Hotspots *smenu;
};

class Mice : public Action {
public:
	Mice(Filename path_, uint32 index_) {
		type = MiceAction;
		path = path_;
		index = index_;
	}
	Filename path;
	uint32 index;
};

class SwapPointer : public Action {
public:
	SwapPointer(uint32 index_) {
		type = SwapPointerAction;
		index = index_;
	}
	uint32 index;
};

class Timer : public Action {
public:
	Timer(uint32 delay_, Common::String flag_) {
		type = TimerAction;
		delay = delay_;
		flag = flag_;
	}
	uint32 delay;
	Common::String flag;
};

class Palette : public Action {
public:
	Palette(Filename path_) {
		type = PaletteAction;
		path = path_;
	}
	Filename path;
};

class Highlight : public Action {
public:
	Highlight(Common::String condition_) {
		type = HighlightAction;
		condition = condition_;
	}
	Common::String condition;
};

class Background : public Action {
public:
	Background(Filename path_, Common::Point origin_, Common::String condition_, Common::String flag1_, Common::String flag2_) {
		type = BackgroundAction;
		path = path_;
		origin = origin_;
		condition = condition_;
		flag1 = flag1_;
		flag2 = flag2_;
	}
	Filename path;
	Common::Point origin;
	Common::String condition;
	Common::String flag1;
	Common::String flag2;
};

class Overlay : public Action {
public:
	Overlay(Filename path_, Common::Point origin_, Common::String flag_) {
		type = OverlayAction;
		path = path_;
		origin = origin_;
		flag = flag_;
	}
	Filename path;
	Common::Point origin;
	Common::String flag;
};

class Escape : public Action {
public:
	Escape() {
		type = EscapeAction;
	}
};

class Save : public Action {
public:
	Save() {
		type = SaveAction;
	}
};

class Load : public Action {
public:
	Load() {
		type = LoadAction;
	}
};

class LoadCheckpoint : public Action {
public:
	LoadCheckpoint() {
		type = LoadCheckpointAction;
	}
};

class Quit : public Action {
public:
	Quit() {
		type = QuitAction;
	}
};

class Cutscene : public Action {
public:
	Cutscene(Filename path_) {
		type = CutsceneAction;
		path = path_;
	}
	Filename path;
};

class Sound : public Action {
public:
	Sound(Filename path_) {
		type = SoundAction;
		path = path_;
	}
	Filename path;
};

class Intro : public Action {
public:
	Intro(Filename path_) {
		type = IntroAction;
		path = path_;
	}
	Filename path;
};

class Play : public Action {
public:
	Play(Filename path_, Common::Point origin_, Common::String condition_, Common::String flag_) {
		type = PlayAction;
		path = path_;
		origin = origin_;
		condition = condition_;
		flag = flag_;
	}
	Filename path;
	Common::Point origin;
	Common::String condition;
	Common::String flag;
};

class Ambient : public Action {
public:
	Ambient(Filename path_, Common::Point origin_, Common::String flag_) {
		type = AmbientAction;
		path = path_;
		origin = origin_;
		flag = flag_;
		fullscreen = false;
		frameNumber = 0;
	}
	Filename path;
	Common::Point origin;
	Common::String flag;
	uint32 frameNumber;
	bool fullscreen;
};

class WalN : public Action {
public:
	WalN(Common::String wn_, Filename path_, Common::Point origin_, Common::String condition_, Common::String flag_) {
		wn = wn_;
		type = WalNAction;
		path = path_;
		origin = origin_;
		condition = condition_;
		flag = flag_;
	}
	Common::String wn;
	Filename path;
	Common::Point origin;
	Common::String condition;
	Common::String flag;
};

class Global : public Action {
public:
	Global(Common::String variable_, Common::String command_) {
		type = GlobalAction;
		variable = variable_;
		command = command_;
	}
	Common::String variable;
	Common::String command;
};

class TalkCommand {
public:
	Common::String command;
	Common::String variable;
	Filename path;
	uint32 num;
	Common::Point position;
};

typedef Common::Array<TalkCommand> TalkCommands;

class Talk : public Action {
public:
	Talk()  {
		type = TalkAction;
		boxPos = Common::Point(0, 0);
		escape = false;
		active = true;
	}

	Talk(Talk *t)  {
		*this = *t;
	}

	TalkCommands commands;
	bool active;
	bool escape;
	Common::Point introPos;
	Filename intro;
	Common::Point boxPos;
	Filename background;
	Common::Point backgroundPos;
	Common::Rect rect;
	Filename second;
	Common::Point secondPos;
};

class ChangeLevel : public Action {
public:
	ChangeLevel(Filename level_) {
		type = ChangeLevelAction;
		level = level_;
	}
	Filename level;
};

enum LevelType {
	TransitionLevel,
	SceneLevel,
	ArcadeLevel,
	CodeLevel
};

class Level {
public:
	Level() {
		type = CodeLevel;
		musicRate = 22050;
		playMusicDuringIntro = false;
		musicStereo = false;
	}
	virtual ~Level() {} // needed to make Level polymorphic
	LevelType type;
	Filenames intros;
	Filename prefix;
	Filename levelIfWin;
	Filename levelIfLose;
	bool playMusicDuringIntro;
	Filename music;
	uint32 musicRate;
	bool musicStereo;
};

class Scene : public Level {
public:
	Scene()  {
		type = SceneLevel;
		resolution = "640x480";
	}
	Common::String resolution;
	Hotspots hots;
};

class FrameInfo {
public:
	FrameInfo(uint32 start_, uint32 length_) {
		start = start_;
		length = length_;
	}

	uint32 lastFrame() {
		return start + length;
	}
	uint32 start;
	uint32 length;
};

enum ScriptMode {
	Interactive = 1,
	NonInteractive,
};

class ScriptInfo {
public:
	ScriptInfo(uint32 time_, uint32 mode_, uint32 actor_, uint32 cursor_) {
		time = time_;
		mode = ScriptMode(mode_);
		actor = actor_;
		cursor = cursor_;
	}
	uint32 time;
	ScriptMode mode;
	uint32 actor;
	uint32 cursor;
};

typedef Common::List<ScriptInfo> Script;

class Shoot {
public:
	Shoot() {
		destroyed = false;
		video = nullptr;
		timesToShoot = 1;
		pointsToShoot = 0;
		attackWeight = 0;
		paletteOffset = 0;
		paletteSize = 0;
		missedAnimation = 0;
		objKillsCount = 0;
		objMissesCount = 0;
		animation = "NONE";
		explosionAnimation = "";
		startFrame = 0;
		lastFrame = 1024;
		interactionFrame = 0;
		noEnemySound = false;
		enemySoundRate = 22050;
		isAnimal = false;
		nonHostile = false;
		playInteractionAudio = false;
		animalSound = "";
		jumpToTimeAfterKilled = 0;
		warningVideoIdx = 0;
		waitForClickAfterInteraction = 0;
		direction = 0;
	}
	Common::String name;
	Filename animation;
	Filename startSound;
	Common::Point position;
	Common::Point deathPosition;


	uint32 timesToShoot;
	uint32 pointsToShoot;
	uint32 attackWeight;

	// Objectives
	uint32 objKillsCount;
	uint32 objMissesCount;

	// Palette
	uint32 paletteOffset;
	uint32 paletteSize;

	// Missed animation
	uint32 missedAnimation;

	// Sounds
	Filename enemySound;
	uint32 enemySoundRate;
	Filename deathSound;
	Filename hitSound;
	Filename animalSound;

	MVideo *video;
	Common::List<uint32> attackFrames;
	Common::Array<FrameInfo> bodyFrames;
	Common::Array<FrameInfo> explosionFrames;
	uint32 startFrame;
	uint32 lastFrame;
	uint32 interactionFrame;
	Filename explosionAnimation;
	Filename additionalVideo;
	bool playInteractionAudio;
	bool destroyed;
	bool noEnemySound;

	// Soldier Boyz specific
	bool nonHostile;
	bool isAnimal;
	Common::String checkIfDestroyed;
	int jumpToTimeAfterKilled;
	char direction;
	uint32 waitForClickAfterInteraction;
	uint32 warningVideoIdx;
};

typedef Common::Array<Shoot> Shoots;

class ShootInfo {
public:
	Common::String name;
	uint32 timestamp;
};

typedef Common::List<ShootInfo> ShootSequence;

class SegmentShoots {
public:
	SegmentShoots() {
		segmentRepetition = 0;
	}
	ShootSequence shootSequence;
	uint32 segmentRepetition;
};

typedef Common::Array<SegmentShoots> SegmentShootsSequence;
typedef Common::Array<Common::String> Sounds;

enum SegmentType {
	Straight,
	Select3,
	TurnLeft3,
	Straight3,
	TurnRight3,
	Select2,
	TurnLeft2,
	TurnRight2,
};

class Segment {
public:
	Segment(byte type_, uint32 start_, uint32 size_)  {
		type = type_;
		start = start_;
		size = size_;
		end = false;
	}

	byte type;
	uint32 start;
	uint32 size;
	bool end;
};

typedef Common::Array<Segment> Segments;

class ArcadeTransition {
public:
	ArcadeTransition(Filename video_, Filename palette_, Filename sound_, uint32 soundRate_, uint32 time_)  {
		video = video_;
		palette = palette_;
		sound = sound_;
		soundRate = soundRate_;
		soundStereo = false;
		loseLevel = false;
		winLevel = false;
		selection = false;
		jumpToTime = 0;
		time = time_;
	}

	Filename video;
	Filename palette;
	Filename sound;
	uint32 soundRate;
	bool soundStereo;
	bool loseLevel;
	bool winLevel;
	bool selection;
	uint32 jumpToTime;
	uint32 time;
};

typedef Common::List<ArcadeTransition> ArcadeTransitions;

class ArcadeShooting : public Level {
public:
	ArcadeShooting()  {
		type = ArcadeLevel;
		health = 100;
		id = 0;
		objKillsRequired[0] = 0;
		objKillsRequired[1] = 0;
		objMissesAllowed[0] = 0;
		objMissesAllowed[1] = 0;
		mouseBox = Common::Rect(0, 0, 320, 200);
		frameDelay = 0;
		targetSoundRate = 0; // TODO: unused
		shootSoundRate = 0;
		enemySoundRate = 0;
		hitSoundRate = 0;
		additionalSoundRate = 0;
		noAmmoSoundRate = 0;
	}
	void clear() {
		nextLevelVideo.clear();
		postStatsVideo.clear();
		backgroundVideo.clear();
		transitions.clear();
		maskVideo.clear();
		player.clear();
		shoots.clear();
		intros.clear();
		defeatNoEnergyFirstVideo.clear();
		defeatMissBossVideo.clear();
		defeatNoEnergySecondVideo.clear();
		missBoss1Video.clear();
		missBoss2Video.clear();
		hitBoss1Video.clear();
		hitBoss2Video.clear();
		beforeVideo.clear();
		briefingVideo.clear();
		additionalVideo.clear();
		additionalSound.clear();
		noAmmoSound.clear();
		segments.clear();
		script.clear();
		objKillsRequired[0] = 0;
		objKillsRequired[1] = 0;
		objMissesAllowed[0] = 0;
		objMissesAllowed[1] = 0;
		mouseBox = Common::Rect(0, 0, 320, 200);
		anchor = Common::Point(0, 0);
		targetSoundRate = 0;
		shootSoundRate = 0;
		enemySoundRate = 0;
		hitSoundRate = 0;
		noAmmoSoundRate = 0;
	}

	uint32 id;
	uint32 frameDelay;
	Common::String mode;
	Common::Rect mouseBox;
	Common::Point anchor;
	ArcadeTransitions transitions;
	Segments segments;

	// Objectives
	uint32 objKillsRequired [2];
	uint32 objMissesAllowed [2];

	// Script
	Script script;

	// Videos
	Filename nextLevelVideo;
	Filename postStatsVideo;
	Filename defeatNoEnergyFirstVideo;
	Filename defeatNoEnergySecondVideo;
	Filename defeatMissBossVideo;
	Filename hitBoss1Video;
	Filename missBoss1Video;
	Filename hitBoss2Video;
	Filename missBoss2Video;
	Filename beforeVideo;
	Filename additionalVideo;
	Filename briefingVideo;

	Filename backgroundVideo;
	Filename backgroundPalette;
	Filename maskVideo;
	Filename player;
	int health;
	Shoots shoots;
	SegmentShootsSequence shootSequence;

	// Sounds
	Filename targetSound;
	uint32 targetSoundRate;
	Filename shootSound;
	uint32 shootSoundRate;
	Filename enemySound;
	uint32 enemySoundRate;
	Filename hitSound;
	uint32 hitSoundRate;
	Filename additionalSound;
	uint32 additionalSoundRate;
	Filename noAmmoSound;
	uint32 noAmmoSoundRate;
};

class Transition : public Level {
public:
	Transition(Common::String level)  {
		type = TransitionLevel;
		nextLevel = level;
		levelEasy = "";
		levelHard = "";
		frameNumber = 0;
		frameImage = "";
	}

	Transition(Common::String easy, Common::String hard)  {
		type = TransitionLevel;
		levelEasy = easy;
		levelHard = hard;
		frameNumber = 0;
		frameImage = "";
	}
	Common::String nextLevel;
	Common::String levelEasy;
	Common::String levelHard;
	Filename frameImage;
	uint32 frameNumber;
};

class Code : public Level {
public:
	Code(Common::String name_)  {
		type = CodeLevel;
		name = name_;
	}
	Common::String name;
};

typedef Common::HashMap<Filename, Level*> Levels;
extern Hotspots *g_parsedHots;
extern ArcadeShooting *g_parsedArc;

class ArcadeStats {
	public:
	ArcadeStats()  {
		livesUsed = 0;
		shootsFired = 0;
		enemyHits = 0;
		enemyTargets = 0;
		targetsDestroyed = 0;
		targetsMissed = 0;
		friendliesEncountered = 0;
		infoReceived = 0;
	}
	uint32 livesUsed;
	uint32 shootsFired;
	uint32 enemyHits;
	uint32 enemyTargets;
	uint32 targetsDestroyed;
	uint32 targetsMissed;
	uint32 friendliesEncountered;
	uint32 infoReceived;
};

} // End of namespace Hypno

#endif