ScummVM API documentation
shared.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  */
12 
13 #ifndef SCUMM_INSANE_REBEL2_SHARED_H
14 #define SCUMM_INSANE_REBEL2_SHARED_H
15 
16 #include "common/keyboard.h"
17 
18 namespace Scumm {
19 
20 enum Rebel2MenuCommand {
21  kRebel2MenuCommandNone,
22  kRebel2MenuCommandUp,
23  kRebel2MenuCommandDown,
24  kRebel2MenuCommandAccept,
25  kRebel2MenuCommandCancel
26 };
27 
28 enum {
29  kRebel2MenuResultCancel = -2,
30  kRebel2MenuResultNone = -1
31 };
32 
34 public:
35  enum Result {
36  kQuit,
37  kComplete,
38  kDeath,
39  kGameOver,
40  kError
41  };
42 
43  virtual ~Rebel2Level1Handler() {}
44  virtual bool shouldQuit() const = 0;
45  virtual Result playAttempt(int &lives) = 0;
46  virtual bool playComplete() = 0;
47  virtual bool playDeath() = 0;
48  virtual bool playRetry(int lives) = 0;
49  virtual bool playGameOver(int lives) = 0;
50 };
51 
52 Rebel2Level1Handler::Result runRebel2Level1(Rebel2Level1Handler &handler, int lives);
53 
54 inline Rebel2MenuCommand getRebel2MenuCommand(const Common::KeyState &key) {
55  switch (key.keycode) {
56  case Common::KEYCODE_UP:
57  return kRebel2MenuCommandUp;
58  case Common::KEYCODE_DOWN:
59  return kRebel2MenuCommandDown;
60  case Common::KEYCODE_RETURN:
61  case Common::KEYCODE_KP_ENTER:
62  return kRebel2MenuCommandAccept;
63  case Common::KEYCODE_ESCAPE:
64  return kRebel2MenuCommandCancel;
65  default:
66  return kRebel2MenuCommandNone;
67  }
68 }
69 
70 inline int applyRebel2MenuCommand(Rebel2MenuCommand command, int itemCount,
71  int &selection) {
72  if (itemCount <= 0)
73  return kRebel2MenuResultNone;
74 
75  switch (command) {
76  case kRebel2MenuCommandUp:
77  if (--selection < 0)
78  selection = itemCount - 1;
79  break;
80  case kRebel2MenuCommandDown:
81  if (++selection >= itemCount)
82  selection = 0;
83  break;
84  case kRebel2MenuCommandAccept:
85  return selection >= 0 && selection < itemCount ? selection : kRebel2MenuResultNone;
86  case kRebel2MenuCommandCancel:
87  return kRebel2MenuResultCancel;
88  default:
89  break;
90  }
91  return kRebel2MenuResultNone;
92 }
93 
94 inline bool updateRebel2Fire(bool pressed, bool wasPressed,
95  bool rapidFire, bool autoFire, int16 &rapidFireCounter) {
96  const bool pressedEdge = pressed && !wasPressed;
97  if (pressedEdge)
98  rapidFireCounter = 0;
99 
100  bool rapidFireShot = false;
101  if (rapidFire) {
102  rapidFireShot = pressed && rapidFireCounter % 5 == 0;
103  rapidFireCounter = (rapidFireCounter + 1) % 5;
104  }
105  return pressedEdge || rapidFireShot || autoFire;
106 }
107 
108 } // End of namespace Scumm
109 
110 #endif
Definition: shared.h:33
KeyCode keycode
Definition: keyboard.h:299
Definition: keyboard.h:294
Definition: actor.h:30