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
|
#include <engine/system.h>
#include <game/math.h>
#include <math.h>
#include "../engine/interface.h"
#include "mapres_col.h"
#include "game_protocol.h"
inline vec2 get_direction(int angle)
{
float a = angle/256.0f;
return vec2(cosf(a), sinf(a));
}
inline vec2 get_dir(float a)
{
return vec2(cosf(a), sinf(a));
}
inline float get_angle(vec2 dir)
{
float a = atan(dir.y/dir.x);
if(dir.x < 0)
a = a+pi;
return a;
}
inline vec2 calc_pos(vec2 p, vec2 v, float gravity, float t)
{
vec2 n;
n.x = p.x + v.x*t;
n.y = p.y + v.y*t - gravity*(t*t);
return n;
}
template<typename T>
inline T saturated_add(T min, T max, T current, T modifier)
{
if(modifier < 0)
{
if(current < min)
return current;
current += modifier;
if(current < min)
current = min;
return current;
}
else
{
if(current > max)
return current;
current += modifier;
if(current > max)
current = max;
return current;
}
}
void move_point(vec2 *inout_pos, vec2 *inout_vel, float elasticity, int *bounces);
void move_box(vec2 *inout_pos, vec2 *inout_vel, vec2 size, float elasticity);
// hooking stuff
enum
{
HOOK_RETRACTED=-1,
HOOK_IDLE=0,
HOOK_FLYING,
HOOK_GRABBED
};
class world_core
{
public:
world_core()
{
mem_zero(players, sizeof(players));
}
class player_core *players[MAX_CLIENTS];
};
class player_core
{
public:
world_core *world;
vec2 pos;
vec2 vel;
vec2 hook_pos;
vec2 hook_dir;
int hook_tick;
int hook_state;
int hooked_player;
int jumped;
player_input input;
void tick();
void move();
void read(const obj_player_core *obj_core);
void write(obj_player_core *obj_core);
void quantize();
};
#define LERP(a,b,t) (a + (b-a) * t)
#define min(a, b) ( a > b ? b : a)
#define max(a, b) ( a > b ? a : b)
inline bool col_check_point(float x, float y) { return col_check_point((int)x, (int)y) != 0; }
inline bool col_check_point(vec2 p) { return col_check_point(p.x, p.y); }
struct mapres_entity
{
int x, y;
int data[1];
};
struct mapres_spawnpoint
{
int x, y;
};
struct mapres_item
{
int x, y;
int type;
};
struct mapres_flagstand
{
int x, y;
};
enum
{
MAPRES_ENTS_START=1,
MAPRES_SPAWNPOINT=1,
MAPRES_ITEM=2,
MAPRES_SPAWNPOINT_RED=3,
MAPRES_SPAWNPOINT_BLUE=4,
MAPRES_FLAGSTAND_RED=5,
MAPRES_FLAGSTAND_BLUE=6,
MAPRES_ENTS_END,
ITEM_NULL=0,
ITEM_WEAPON_GUN=0x00010001,
ITEM_WEAPON_SHOTGUN=0x00010002,
ITEM_WEAPON_ROCKET=0x00010003,
ITEM_WEAPON_SNIPER=0x00010004,
ITEM_WEAPON_HAMMER=0x00010005,
ITEM_HEALTH =0x00020001,
ITEM_ARMOR=0x00030001,
ITEM_NINJA=0x00040001,
};
|