2007-11-25 19:42:40 +00:00
|
|
|
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
2008-01-12 17:09:00 +00:00
|
|
|
#ifndef GAME_GAME_H
|
|
|
|
#define GAME_GAME_H
|
|
|
|
|
2007-12-15 10:24:49 +00:00
|
|
|
#include <engine/e_system.h>
|
2008-01-19 10:57:25 +00:00
|
|
|
#include <engine/e_common_interface.h>
|
2007-05-22 15:03:32 +00:00
|
|
|
#include <math.h>
|
2008-06-12 12:09:34 +00:00
|
|
|
#include "g_math.hpp"
|
|
|
|
#include "g_collision.hpp"
|
2008-07-06 11:21:21 +00:00
|
|
|
#include <game/generated/g_protocol.hpp>
|
2007-08-22 21:13:33 +00:00
|
|
|
|
2008-06-12 10:51:48 +00:00
|
|
|
struct TUNING_PARAMS
|
2008-02-02 12:38:36 +00:00
|
|
|
{
|
2008-06-12 10:51:48 +00:00
|
|
|
TUNING_PARAMS()
|
2008-02-02 12:38:36 +00:00
|
|
|
{
|
|
|
|
const float ticks_per_second = 50.0f;
|
2008-03-22 14:42:35 +00:00
|
|
|
#define MACRO_TUNING_PARAM(name,value) name.set((int)(value*100.0f));
|
2008-06-12 12:09:34 +00:00
|
|
|
#include "g_tuning.hpp"
|
2008-02-02 12:38:36 +00:00
|
|
|
#undef MACRO_TUNING_PARAM
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *names[];
|
|
|
|
|
|
|
|
#define MACRO_TUNING_PARAM(name,value) tune_param name;
|
2008-06-12 12:09:34 +00:00
|
|
|
#include "g_tuning.hpp"
|
2008-02-02 12:38:36 +00:00
|
|
|
#undef MACRO_TUNING_PARAM
|
|
|
|
|
2008-06-12 10:51:48 +00:00
|
|
|
static int num() { return sizeof(TUNING_PARAMS)/sizeof(int); }
|
2008-02-02 12:38:36 +00:00
|
|
|
bool set(int index, float value);
|
|
|
|
bool set(const char *name, float value);
|
|
|
|
bool get(int index, float *value);
|
|
|
|
bool get(const char *name, float *value);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
inline vec2 get_direction(int angle)
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
|
|
|
float a = angle/256.0f;
|
2007-08-22 07:52:33 +00:00
|
|
|
return vec2(cosf(a), sinf(a));
|
2007-05-22 15:03:32 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 15:32:54 +00:00
|
|
|
inline vec2 get_dir(float a)
|
|
|
|
{
|
|
|
|
return vec2(cosf(a), sinf(a));
|
|
|
|
}
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
inline float get_angle(vec2 dir)
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
|
|
|
float a = atan(dir.y/dir.x);
|
|
|
|
if(dir.x < 0)
|
2007-08-22 07:52:33 +00:00
|
|
|
a = a+pi;
|
2007-05-22 15:03:32 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2007-09-09 18:21:14 +00:00
|
|
|
|
2008-03-16 22:32:17 +00:00
|
|
|
inline vec2 calc_pos(vec2 p, vec2 v, float curvature, float speed, float t)
|
2007-11-11 21:02:36 +00:00
|
|
|
{
|
|
|
|
vec2 n;
|
2008-03-16 22:32:17 +00:00
|
|
|
t *= speed;
|
2007-11-11 21:02:36 +00:00
|
|
|
n.x = p.x + v.x*t;
|
2008-03-16 22:32:17 +00:00
|
|
|
n.y = p.y + v.y*t + curvature/10000*(t*t);
|
2007-11-11 21:02:36 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-09 18:21:14 +00:00
|
|
|
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);
|
2007-12-12 19:52:57 +00:00
|
|
|
bool test_box(vec2 pos, vec2 size);
|
2008-03-16 22:32:17 +00:00
|
|
|
float velocity_ramp(float value, float start, float range, float curvature);
|
2007-09-09 18:21:14 +00:00
|
|
|
|
|
|
|
// hooking stuff
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
HOOK_RETRACTED=-1,
|
|
|
|
HOOK_IDLE=0,
|
2008-03-22 13:03:52 +00:00
|
|
|
HOOK_RETRACT_START=1,
|
|
|
|
HOOK_RETRACT_END=3,
|
2007-09-09 18:21:14 +00:00
|
|
|
HOOK_FLYING,
|
2007-12-09 12:40:34 +00:00
|
|
|
HOOK_GRABBED,
|
|
|
|
|
|
|
|
COREEVENT_GROUND_JUMP=0x01,
|
|
|
|
COREEVENT_AIR_JUMP=0x02,
|
|
|
|
COREEVENT_HOOK_LAUNCH=0x04,
|
|
|
|
COREEVENT_HOOK_ATTACH_PLAYER=0x08,
|
|
|
|
COREEVENT_HOOK_ATTACH_GROUND=0x10,
|
|
|
|
COREEVENT_HOOK_RETRACT=0x20,
|
2007-09-09 18:21:14 +00:00
|
|
|
};
|
|
|
|
|
2008-06-12 10:51:48 +00:00
|
|
|
class WORLD_CORE
|
2007-09-09 18:21:14 +00:00
|
|
|
{
|
|
|
|
public:
|
2008-06-12 10:51:48 +00:00
|
|
|
WORLD_CORE()
|
2007-09-09 18:21:14 +00:00
|
|
|
{
|
2008-07-06 11:21:21 +00:00
|
|
|
mem_zero(characters, sizeof(characters));
|
2007-09-09 18:21:14 +00:00
|
|
|
}
|
2008-02-02 12:38:36 +00:00
|
|
|
|
2008-06-12 10:51:48 +00:00
|
|
|
TUNING_PARAMS tuning;
|
2008-07-06 11:21:21 +00:00
|
|
|
class CHARACTER_CORE *characters[MAX_CLIENTS];
|
2007-09-09 18:21:14 +00:00
|
|
|
};
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
class CHARACTER_CORE
|
2007-09-09 18:21:14 +00:00
|
|
|
{
|
|
|
|
public:
|
2008-06-12 10:51:48 +00:00
|
|
|
WORLD_CORE *world;
|
2007-09-09 18:21:14 +00:00
|
|
|
|
|
|
|
vec2 pos;
|
|
|
|
vec2 vel;
|
|
|
|
|
|
|
|
vec2 hook_pos;
|
|
|
|
vec2 hook_dir;
|
|
|
|
int hook_tick;
|
|
|
|
int hook_state;
|
|
|
|
int hooked_player;
|
|
|
|
|
|
|
|
int jumped;
|
2008-02-24 16:03:58 +00:00
|
|
|
NETOBJ_PLAYER_INPUT input;
|
2007-09-09 18:21:14 +00:00
|
|
|
|
2007-12-09 12:40:34 +00:00
|
|
|
int triggered_events;
|
|
|
|
|
2008-02-24 18:41:02 +00:00
|
|
|
void reset();
|
2007-09-09 18:21:14 +00:00
|
|
|
void tick();
|
|
|
|
void move();
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
void read(const NETOBJ_CHARACTER_CORE *obj_core);
|
|
|
|
void write(NETOBJ_CHARACTER_CORE *obj_core);
|
2007-09-09 18:21:14 +00:00
|
|
|
void quantize();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-07-21 19:03:50 +00:00
|
|
|
#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)
|
|
|
|
|
2008-01-13 11:15:32 +00:00
|
|
|
inline bool col_check_point(float x, float y) { return col_is_solid((int)x, (int)y) != 0; }
|
2007-08-22 07:52:33 +00:00
|
|
|
inline bool col_check_point(vec2 p) { return col_check_point(p.x, p.y); }
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2008-01-12 17:09:00 +00:00
|
|
|
#endif
|