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
33namespace Hopkins {
34
36 bool forward;
37 bool backward;
38 bool turnLeft;
39 bool turnRight;
40 bool fire;
41 bool exitRequested;
42 bool contextRequested;
43 bool toggleTextures;
44
45 BaseInputState() : forward(false), backward(false), turnLeft(false),
46 turnRight(false), fire(false), exitRequested(false), contextRequested(false),
47 toggleTextures(false) {}
48};
49
50enum BaseSoundEvent {
51 kBaseSoundEnemyShot = 2,
52 kBaseSoundPlayerShot = 3,
53 kBaseSoundDoorOrExit = 4,
54 kBaseSoundGuardHit = 5
55};
56
58public:
59 explicit BaseEngine(const BaseData &data);
60
61 void initialize(const BaseEntryPoint &entry);
62
64 int tick(BaseInputState &input);
65
66 const BaseData &data() const { return _data; }
67 const uint16 *xGrid() const { return _xGrid; }
68 const uint16 *yGrid() const { return _yGrid; }
69 const BaseObject &object(int id) const { return _objects[id]; }
70 const BaseDoor &door(int id) const { return _doors[id]; }
71 const Common::Array<int> &soundEvents() const { return _soundEvents; }
72 void clearSoundEvents() { _soundEvents.clear(); }
73
74 int playerX() const { return _playerX; }
75 int playerY() const { return _playerY; }
76 int playerAngle() const { return _playerAngle; }
77 int health() const { return _health; }
78 int weaponCounter() const { return _weaponCounter; }
79 bool texturesEnabled() const { return _texturesEnabled; }
80 int entryReturnId() const { return _entry ? _entry->returnId : 0; }
81
82 BaseRayHit castRay(int angle, int viewColumn) const;
83 BaseRayHit castRayFrom(int16 originX, int16 originY, int angle, int viewColumn) const;
84 int objectAngle(int32 deltaX, int32 deltaY) const;
85 int objectDistance(const BaseObject &object) const;
86
87private:
88 void buildGrid();
89 void createObjects();
90 void updateTurn(const BaseInputState &input);
91 void updatePlayer(const BaseInputState &input);
92 void updateWeapon(const BaseInputState &input);
93 void updateDoors();
94 void updateGuards();
95 void updateGuard(BaseObject &object);
96
97 uint16 getWallX(int mapPos) const;
98 uint16 getWallY(int mapPos) const;
99 int moveWithAckCollision(int16 &x, int16 &y, int angle, int amount, int ignoredObject) const;
100 int movePlayer(int angle, int amount);
101 int moveObject(int objectId, int angle, int amount);
102 int checkObjectPosition(int16 x, int16 y, int ignoredObject) const;
103 int checkObjectPositionShot(int16 x, int16 y, int angle);
104 int checkHitAt(int16 x, int16 y, int angle) const;
105 int moveShotStep(int16 &x, int16 &y, int angle, int amount);
106 int testGuardShotPosition(int16 x, int16 y) const;
107 bool testWall(int mapPos) const;
108
109 int checkDoorOpen(int16 x, int16 y, int angle);
110 void checkDoors();
111 int findDoor(int mapPos) const;
112 int findDoorSlot(int mapPos) const;
113 const BaseDoor *doorForMapPosition(int mapPos) const;
114 BaseDoor *doorForMapPosition(int mapPos);
115 int doorOffsetForMapPosition(int mapPos) const;
116
117 bool guardCanShoot(int objectId);
118 void fireWeapon();
119 int tryExit() const;
120
121 int castXRay(int16 originX, int16 originY, int angle, BaseRayHit &hit) const;
122 int castYRay(int16 originX, int16 originY, int angle, BaseRayHit &hit) const;
123 void finalizeRayDistance(BaseRayHit &hit, int viewColumn) const;
124
125 const BaseData &_data;
126 const BaseEntryPoint *_entry;
127 uint16 _xGrid[kBaseAckGridArray];
128 uint16 _yGrid[kBaseAckGridArray];
129 BaseObject _objects[kBaseMaxObjects + 1];
130 BaseDoor _doors[kBaseMaxDoors];
131
132 int16 _playerX;
133 int16 _playerY;
134 int16 _playerAngle;
135 int _health;
136 int _weaponCounter;
137 bool _texturesEnabled;
138 int _lastObjectHit;
139
140 // Original keyboard inertia: apply the previous delta, halve the ramp,
141 // then build the next pending turn from the currently held key.
142 int _turnRamp;
143 int _pendingTurn;
144
145 Common::Array<int> _soundEvents;
146};
147
148} // End of namespace Hopkins
149
150#endif // HOPKINS_BASE_ENGINE_H
void clear()
Definition: array.h:321
Definition: base_data.h:35
Definition: base_engine.h:57
int tick(BaseInputState &input)
Definition: anim.h:30
Definition: base_types.h:181
Definition: base_engine.h:35