forked from cnlohr/noeuclid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameMap.h
118 lines (103 loc) · 4.12 KB
/
GameMap.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
#ifndef GAMEMAP_H
#define GAMEMAP_H
//Define all lava/death blocks.
//If the user touches one, he dies.
#define MAX_DEATH_BLOCKS 8192
#define MAX_PICKABLES 256
#include <functional>
#include "scripthelpers.h"
using initfn = std::function<void()>;
using runfn = std::function<void(double timeIn)>;
#include "Room.h"
#include "TCC.h"
#include <unordered_map>
extern TCC tcc;
class GameMap {
public:
int lastroom = -1, curroom = 0, startroom = 0;
DeathBlock DeathBlocks[MAX_DEATH_BLOCKS];
PickableBlock PBlocks[MAX_PICKABLES];
vector<Room> rooms;
void update();
void die();
void setRoom(int newroom, bool reset = false);
void collision(struct CollisionProbe * ddat);
#define DONE (i>>ws).eof()
/**
* A list of functions that return partially apply the utility functions
* removing their parameters so that they can then be run when a room is initialized or updated
* TODO code is hard to read
*/
unordered_map<string, std::function<initfn(istream&)>> initfuncs {
{"EmptyBox", [](istream& i) -> initfn {
Vec3i p,s; BlockType b; i>>p>>s>>b;
int density = DEFAULT_DENSITY; if(!DONE) i>>density;
return bind(EmptyBoxV, p, s, true, RGBA{1, DEFAULT_BRIGHT, byte(density), static_cast<byte>(b)});
}}, {"Cell", [](istream& i) -> initfn {
Vec3i p; BlockType b; i>>p>>b;
return bind(ChangeCellV, 0, p, RGBA{1, DEFAULT_BRIGHT, 255, static_cast<byte>(b)});
}}, {"ClearCell", [](istream& i) -> initfn {
Vec3i p; i>>p; //TODO merge with "Block"
return bind(ChangeCellV, 0, p, RGBA{0, DEFAULT_BRIGHT, 0, DEFAULT_EMPTY_BLOCK});
}}, {"ClearRange", [](istream& i) -> initfn {
Vec3i p,s; i>>p>>s;
return bind(ClearRangeV, p, s);
}}, {"PaintRange", [](istream& i) -> initfn {
Vec3i p,s; BlockType b; i>>p>>s>>b;
int density = DEFAULT_DENSITY; if(!DONE) i>>density;
return bind(PaintRangeV, p, s, RGBA{1,190,byte(density),static_cast<byte>(b)});
}}, {"Warp", [](istream& i) -> initfn {
Vec3i p,s; Vec3f x;
i>>p>>s>>x;
return bind(WarpSpaceV, p, s, x);
}}, {"JumpSection", [](istream& i) -> initfn {
Vec3i p,s; Vec3f ofs, f1 = {1,0,0},f2={0,1,0},f3={0,0,1};
i>>p>>s>>ofs;
if(!DONE) i>>f1>>f2>>f3;
return bind(JumpSpaceV, p, s, ofs, f1, f2, f3);
}}, {"RequireRoom", [this](istream& i) -> initfn {
int room; i>>room;
return [this,room]() { rooms[room].begin(); };
}}
};
unordered_map<string, function<runfn(istream&)>> runfuncs {
{"AnimateOpen", [](istream& i) -> runfn {
Vec3i p,s; i>>p>>s;
return [p,s](double timeIn) {
int capden = 255 - timeIn * 200;
PaintRangeV(p, s, {1, 190, byte(capden<0?0:capden), GOAL_BLOCK});
};
}}, {"AnimateClose", [](istream& i) -> runfn {
Vec3i p,s; i>>p>>s;
return [p,s](double timeIn) {
int capden = 255 - timeIn * 200;
PaintRangeV(p, s, {1,190,byte(capden<0?255:255-capden),DEADGOAL_BLOCK});
};
}}, {"DieInRange", [](istream& i) -> runfn {
Vec3f p,s; i>>p>>s;
return [p,s](double timeIn) {
if (PlayerInRangeV(p,s)) ::die();
};
}}
};
unordered_map<string, int> aliases;
void AddDeathBlock(Vec3i p);
bool IsOnDeathBlock(Vec3i p);
//Returns id if pickable is there.
//Returns -1 if no block.
//Returns -2 if block tween incomplete.
int GetPickableAt(Vec3i p);
void DissolvePickable(int pid);
//If -1, no pickables left.
//If -2, Pickable already there.
//Otherwise returns which pickable!
//initial_density should be 0 unless you want to shorten (+) or lengthen (-) tween.
int PlacePickableAt(Vec3i p, float initial_density);
void ClearPickableBlocks();
//Redraw
void UpdatePickableBlocks();
void PickableClick(bool left, Vec3f p, float dist);
private:
void loadRooms(string fname);
};
#endif /* GAMEMAP_H */