-
Notifications
You must be signed in to change notification settings - Fork 5
/
scene.h
349 lines (297 loc) · 10.8 KB
/
scene.h
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
/*
Copyright 2013-2015 Rohit Nirmal
This file is part of Clonepoint.
Clonepoint 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.
Clonepoint 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 Clonepoint. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SCENE_H
#define SCENE_H
#include <vector>
#include "entity.h"
#include "locator.h"
#include "map.h"
#include "intersect.h"
#define MAX_SAVES 3
class Scene;
typedef void (Scene::*interpFunc) (Entity*, vec2f, vec2f, int*, bool*, bool*, vec2f*);
enum TraceDirection
{
TDHorizontal = 0,
TDVertical
};
enum UsableEnts
{
UESwitch = 0,
UETerminal,
UEElevator,
UECircuitBox,
UEStairs,
UEEnemy,
UEEnemyKnockedOut,
NumUsableEnts
};
enum SavedGameEntityType
{
SGET_Unknown = 0,
SGET_Player,
SGET_Door,
SGET_Enemy,
SGET_Objective,
SGET_CircuitBox,
SGET_LightFixture,
SGET_Glass,
SGET_Alarm,
SGET_ElevatorDoor
};
struct SavedGameHeader
{
char filename[32];
int numLinks;
int numEnts;
bool playerFiredShot;
unsigned int timeToSniper;
unsigned int numPlayerBullets;
unsigned int playerEnergy;
};
struct SavedGameLink
{
vec2f start;
vec2f end;
};
struct SavedGameEntityState
{
SavedGameEntityType type;
vec2f position;
vec2f velocity;
//Living Entity
Direction dir;
int stairTimer;
bool onGround;
bool alive;
//Door
int timeToClose; //for trap doors only.
//Enemy
GuardState gs;
TargetType targetType;
AlertType alertType;
vec2f targetLocation;
//Player
AttachType at;
//Generic
//for player: index of attached collision volume.
//for guard: index of targeted light switch.
//for door: index of this door in level entity vector.
//for main computer: index of this objective in level entity vector.
//for glass collision volumes: index of this level collision volume vector.
//for circuit box: index of this circuit box in level entity vector.
int index1;
//for player: index of entered elevator.
//for guard: index of light to activate (if off).
int index2;
//for player: number of incomplete objectives.
//for guard: index of this guard in level entity vector.
int index3;
//for guard: reaction time before shooting.
int index4;
//for guard: index of secondary target entity.
int index5;
//to save on space, b1 is used for several
//different bools of linkable entities, and also
//for whether an enemy is patrolling on spawn.
bool b1;
//enemy: canSeePlayer
bool b2;
//enemy
EnemyShotResolve esr;
};
class Scene
{
public:
Scene();
~Scene();
void loadMap(const char* filename, bool savegame);
void reloadMap();
void update(unsigned int dT);
void updateEnemy(Enemy* enemy, unsigned int dT);
void updateMotionScanner(MotionScanner* scanner);
void updateSecurityCamera(SecurityCamera* camera);
bool handleMotionScannerWithEnt(MotionScanner* scanner, LivingEntity* le);
void updatePowerSocket(PowerSocket* socket);
void checkDoorHitEnemy(Door* door);
void updateCamera();
void setCameraDims(int w, int h);
void movePlayer(bool left, bool right, bool down, bool up);
Map* getMap();
vec2f getPlayerPosition();
vec2f getMouseDragPosition();
Rect getCamera();
Player* getPlayer();
vec2f getTrajPointAt(int i);
size_t getNumberOfTrajPoints();
void calculateJumpTrajectory(int x, int y, unsigned int dT);
bool inCrosslinkMode();
bool isPlayerSelecting();
void setPlayerSelecting(bool b);
void toggleCrosslinkMode();
void handleClick(int mx, int my, unsigned int dT);
void handleLeftClickRelease(int mx, int my);
void addNoise(int x, int y, int radius, bool alertGuards, AlertType atype, Alarm* alarm);
//Nonlinkable entities that player can interact with
LinkableEntity* getLinker();
void warpPlayerTo(int mx, int my);
void endLevel();
bool isLevelOver();
bool isDetachmentDelayed();
void resetDelayDetachment();
bool isElevatorLocked();
void resetElevatorLock();
void handleStairCollision(LivingEntity* le);
void computeVisibility(FieldOfView* fov);
void updateVisibility(FieldOfView* fov, int angle1, int angle2);
void updateOverlappingFOVs(Door* door); //called when door is opened or closed.
void calculatePlayerVisibility();
bool isPlayerInFOV(FieldOfView* fov);
void calculateStrongestLight(Enemy* enemy);
Door* getDoorOfCollisionVolume(CollisionVolume* vol);
void calculateOverlappingLightsOfDoor(Door* door);
bool isCircuitUnlocked(Circuit c);
void getCircuitColor(Circuit c, float &r, float &g, float &b);
void crosslinkPan(int mouseX, int mouseY);
void handleVaultDoorClose(Door* door);
bool isPlayerInLight();
void addPlayerJumpPower(float f);
void subPlayerJumpChargeTime(int dec);
Particle* getParticleAt(size_t i);
size_t getNumberOfParticles();
void handleMouse(unsigned int mx, unsigned int my);
MouseOverObject getObjectMousedOver();
float getLightEnteredAlpha();
float getInputPopupAlpha();
bool hasPlayerFiredShot();
int getStringMessageTime();
StringMessage getStringMessage();
UsableEnts getFirstOverlappedEnt();
//scene_guards.cpp
void traceEnemyFOV(Enemy* enemy);
void handleEnemyLightOff(Enemy* enemy);
void handleEnemyPathfind(Enemy* enemy);
void enemyTryOpenDoor(Enemy* enemy, Door* door);
// void handlePathfindEnd(Enemy* enemy);
bool stairsReachableToEnemy(Enemy* enemy, Stairs* stairs);
bool switchReachableToEnemy(Enemy* enemy, LightSwitch* ls);
//scene_physics.cpp
void handleMapCollisions(LivingEntity* ent, unsigned int dT);
void handleParticles();
void glassShatter(CollisionVolume* vol, vec2f velocity);
bool checkIfEntOnGround(LivingEntity* ent);
void checkPlayerClimbFinish();
void checkPlayerClimbDownFinish();
void checkPlayerCeilingEnd();
void tryPlayerAttachSide();
void handlePlayerFrob(bool up);
void handlePlayerPounceEnemy(Enemy* enemy, unsigned int dT);
void handlePlayerShotWhileAttached();
//scene_saved_game.cpp
void loadGame(const char* filename);
void saveGame(const char* filename);
void getLinks(std::vector<SavedGameLink>* container);
void getSGESs(std::vector<SavedGameEntityState>* container);
void updateSaves(unsigned int dT);
bool isLoadMenuVisible();
void showLoadMenu(bool b);
int getSaveTimeAt(unsigned int index);
void loadAutosave(unsigned int index);
void setTimeAt(unsigned int index, unsigned int time);
int getSecondsSince(unsigned int index);
vec2f getLaserEnd();
//scene_trace.cpp
bool isTraceBlocked(Entity* source, vec2f a, vec2f b, vec2f* c, int* volIndex, bool* isDoor, float vertEpsilon, interpFunc func);
bool traceInDirection(Entity* source, vec2f a, vec2f b, vec2f* end, bool downOrRight, TraceDirection direction, int* volIndex, bool* isDoor, interpFunc func);
void traceBullet(LivingEntity* entity, vec2f target, GunShotTraceType gstt, bool fired);
void handleTraceHit(vec2f* oldv3interp, vec2f* v3interp, vec2f* c, CollisionVolume* volume);
bool handleTraceHitMapBounds(vec2f* v3interp, vec2f* c);
void bulletFiredFromEnemy(Entity* source, vec2f interpolatedPoint, vec2f start, int* index, bool* b1, bool* stop, vec2f* end);
void bulletFiredFromEnemyInvoluntary(Entity* source, vec2f interpolatedPoint, vec2f start, int* index, bool* b1, bool* stop, vec2f* end);
void bulletFiredFromPlayer(Entity* source, vec2f interpolatedPoint, vec2f start, int* index, bool* b1, bool* stop, vec2f* end);
void traceLaserSight(Entity* source, vec2f interpolatedPoint, vec2f start, int* index, bool* b1, bool* stop, vec2f* end);
void traceGuardSight(Entity* source, vec2f interpolatedPoint, vec2f start, int* index, bool* b1, bool* stop, vec2f* end);
void interpStandard(Entity* source, vec2f interpolatedPoint, vec2f start, int* index, bool* b1, bool* stop, vec2f* end);
void breakOnGlass(vec2f interpolatedPoint, vec2f start, bool* stop);
void killEnemies(Entity* source, vec2f interpolatedPoint, bool* stop);
bool isMouseCursorSeen(int mx, int my);
unsigned int _numPlayerBullets;
int _timeToSniper;
unsigned int _playerEnergy;
private:
void makeInitialLinks();
void attemptLinkBetween(vec2f p1, vec2f p2);
void attemptLightLinkBetween(vec2f p1, vec2f p2);
void addParticle(float x, float y, float vx, float vy);
void playerJump();
void setNewLinkAt(int mx, int my);
vec2f _mouseDragPos; //used to draw link from an linkableEnd to the mouse pointer when being moved by player.
Player* _player;
Map* _currentMap;
size_t _numCollideVols;
Rect _camera;
vec2f _trajPoints[200];
size_t _stopTrajPoint;
bool _crosslink; //are we in crosslink mode?
bool _selecting; //is the user currently setting a link?
//Nonlinkable entities that player can interact with...besides stairs.
LinkableEntity* _linker; //pointer to linkableEntity that player is currently choosing a target for.
LightSwitch* _switcher; //pointer to light switch that player may overlap.
MainComputer* _computer; //pointer to main objective computer that player may overlap.
ElevatorDoor* _elevator;
CircuitBox* _circuitBox;
bool _showInputPopup;
vec2f _jumpImpulse;
vec2f _laserEnd;
//is the player overlapping with any of these?
bool _playerOverlappingEnts[NumUsableEnts];
unsigned int _totalObjectives; //starts out as the number of MainComputers in currentMap. Decreases as player deactivates them. Used to check for level end condition.
Rect _endRect; //player ends the level by completing all objectives and colliding with this.
//used to iterate linkable entities only.
std::vector<LinkableEntity*>::iterator linkBegin;
std::vector<LinkableEntity*>::iterator linkEnd;
std::vector<LinkableEntity*>::iterator linkIter;
//statistics
unsigned int _numEnemies;
int _jumpPowerTimer; //time that LMB is held for calculating jump power. Starts at time depending on player's jump level, then decreases to zero.
float _jumpPower; //ranges from 0 to 1.
float _playerJumpPower;
int _timeToFullChargeJump;
bool _levelOver; //set to true when player intersects objectives met and objectivesIncomplete is 0. Used to switch game state.
bool _moveDelay; //set to true when player switches attachment from side to ceiling or vice-versa. Set to false when movement keys are released. Made to ensure player does not immediate detach.
bool _elevatorLocked;
//used to simplify movement code.
AttachType _testAttach;
//unused variables for calls to trace functions.
vec2f _unused_c;
int _unused_index;
bool _unused_bool;
bool _circuitUnlocked[4];
std::vector<Particle*> _particles;
MouseOverObject _mousedOverObject;
int _stringMessageTimer;
float _lightEnteredAlpha;
float _inputPopupAlpha;
bool _playerShotFired;
StringMessage _stringMessage;
//saving
char _mapFilename[32];
unsigned int _currentSave;
int _saveTimer;
char _saveFilename[16];
bool _loadMenuVisible;
int _saveTimeSince[MAX_SAVES];
};
#endif