ScummVM API documentation
base_engine.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  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 // Source-backed Hopkins WBASE simulation state.
23 
24 #ifndef HOPKINS_BASE_ENGINE_H
25 #define HOPKINS_BASE_ENGINE_H
26 
27 #include "hopkins/base_data.h"
28 #include "hopkins/base_types.h"
29 
30 #include "common/array.h"
31 #include "common/scummsys.h"
32 
33 namespace Hopkins {
34 
36  bool forward;
37  bool backward;
38  bool turnLeft;
39  bool turnRight;
40  bool fire;
41  bool exitRequested;
42  bool toggleTextures;
43 
44  BaseInputState() : forward(false), backward(false), turnLeft(false),
45  turnRight(false), fire(false), exitRequested(false), toggleTextures(false) {}
46 };
47 
48 enum BaseSoundEvent {
49  kBaseSoundEnemyShot = 2,
50  kBaseSoundPlayerShot = 3,
51  kBaseSoundDoorOrExit = 4,
52  kBaseSoundGuardHit = 5
53 };
54 
55 class BaseEngine {
56 public:
57  explicit BaseEngine(const BaseData &data);
58 
59  void initialize(const BaseEntryPoint &entry);
60 
62  int tick(BaseInputState &input);
63 
64  const BaseData &data() const { return _data; }
65  const uint16 *xGrid() const { return _xGrid; }
66  const uint16 *yGrid() const { return _yGrid; }
67  const BaseObject &object(int id) const { return _objects[id]; }
68  const BaseDoor &door(int id) const { return _doors[id]; }
69  const Common::Array<int> &soundEvents() const { return _soundEvents; }
70  void clearSoundEvents() { _soundEvents.clear(); }
71 
72  int playerX() const { return _playerX; }
73  int playerY() const { return _playerY; }
74  int playerAngle() const { return _playerAngle; }
75  int health() const { return _health; }
76  int weaponCounter() const { return _weaponCounter; }
77  bool texturesEnabled() const { return _texturesEnabled; }
78  int entryReturnId() const { return _entry ? _entry->returnId : 0; }
79 
80  BaseRayHit castRay(int angle, int viewColumn) const;
81  BaseRayHit castRayFrom(int16 originX, int16 originY, int angle, int viewColumn) const;
82  int objectAngle(int32 deltaX, int32 deltaY) const;
83  int objectDistance(const BaseObject &object) const;
84 
85 private:
86  void buildGrid();
87  void createObjects();
88  void updateTurn(const BaseInputState &input);
89  void updatePlayer(const BaseInputState &input);
90  void updateWeapon(const BaseInputState &input);
91  void updateDoors();
92  void updateGuards();
93  void updateGuard(BaseObject &object);
94 
95  uint16 getWallX(int mapPos) const;
96  uint16 getWallY(int mapPos) const;
97  int moveWithAckCollision(int16 &x, int16 &y, int angle, int amount, int ignoredObject) const;
98  int movePlayer(int angle, int amount);
99  int moveObject(int objectId, int angle, int amount);
100  int checkObjectPosition(int16 x, int16 y, int ignoredObject) const;
101  int checkObjectPositionShot(int16 x, int16 y, int angle);
102  int checkHitAt(int16 x, int16 y, int angle) const;
103  int moveShotStep(int16 &x, int16 &y, int angle, int amount);
104  int testGuardShotPosition(int16 x, int16 y) const;
105  bool testWall(int mapPos) const;
106 
107  int checkDoorOpen(int16 x, int16 y, int angle);
108  void checkDoors();
109  int findDoor(int mapPos) const;
110  int findDoorSlot(int mapPos) const;
111  const BaseDoor *doorForMapPosition(int mapPos) const;
112  BaseDoor *doorForMapPosition(int mapPos);
113  int doorOffsetForMapPosition(int mapPos) const;
114 
115  bool guardCanShoot(int objectId);
116  void fireWeapon();
117  int tryExit() const;
118 
119  int castXRay(int16 originX, int16 originY, int angle, BaseRayHit &hit) const;
120  int castYRay(int16 originX, int16 originY, int angle, BaseRayHit &hit) const;
121  void finalizeRayDistance(BaseRayHit &hit, int viewColumn) const;
122 
123  const BaseData &_data;
124  const BaseEntryPoint *_entry;
125  uint16 _xGrid[kBaseAckGridArray];
126  uint16 _yGrid[kBaseAckGridArray];
127  BaseObject _objects[kBaseMaxObjects + 1];
128  BaseDoor _doors[kBaseMaxDoors];
129 
130  int16 _playerX;
131  int16 _playerY;
132  int16 _playerAngle;
133  int _health;
134  int _weaponCounter;
135  bool _texturesEnabled;
136  int _lastObjectHit;
137 
138  // Original keyboard inertia: apply the previous delta, halve the ramp,
139  // then build the next pending turn from the currently held key.
140  int _turnRamp;
141  int _pendingTurn;
142 
143  Common::Array<int> _soundEvents;
144 };
145 
146 } // End of namespace Hopkins
147 
148 #endif // HOPKINS_BASE_ENGINE_H
Definition: base_engine.h:55
void clear()
Definition: array.h:321
Definition: base_types.h:145
Definition: base_types.h:181
Definition: base_types.h:165
Definition: base_types.h:131
Definition: base_engine.h:35
Definition: anim.h:30
Definition: base_data.h:35