2007-11-25 19:42:40 +00:00
|
|
|
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
2007-12-15 10:24:49 +00:00
|
|
|
#include <engine/e_system.h>
|
|
|
|
#include <game/g_math.h>
|
2007-05-22 15:03:32 +00:00
|
|
|
#include <math.h>
|
2007-12-15 10:24:49 +00:00
|
|
|
#include "../engine/e_interface.h"
|
|
|
|
#include "g_mapres_col.h"
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2007-12-15 10:24:49 +00:00
|
|
|
#include "g_protocol.h"
|
2007-08-22 21:13:33 +00:00
|
|
|
|
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
|
|
|
|
2007-11-11 21:02:36 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2007-09-09 18:21:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
// hooking stuff
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
HOOK_RETRACTED=-1,
|
|
|
|
HOOK_IDLE=0,
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2007-12-09 12:40:34 +00:00
|
|
|
int triggered_events;
|
|
|
|
|
2007-09-09 18:21:14 +00:00
|
|
|
void tick();
|
|
|
|
void move();
|
|
|
|
|
|
|
|
void read(const obj_player_core *obj_core);
|
|
|
|
void write(obj_player_core *obj_core);
|
|
|
|
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)
|
|
|
|
|
2007-07-13 21:22:45 +00:00
|
|
|
inline bool col_check_point(float x, float y) { return col_check_point((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
|
|
|
|
2007-08-30 07:15:26 +00:00
|
|
|
struct mapres_entity
|
|
|
|
{
|
|
|
|
int x, y;
|
2007-10-28 23:14:18 +00:00
|
|
|
int data[1];
|
2007-08-30 07:15:26 +00:00
|
|
|
};
|
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
struct mapres_spawnpoint
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mapres_item
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
int type;
|
|
|
|
};
|
|
|
|
|
2007-08-30 07:15:26 +00:00
|
|
|
struct mapres_flagstand
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
enum
|
|
|
|
{
|
2007-08-30 07:15:26 +00:00
|
|
|
MAPRES_ENTS_START=1,
|
2007-05-22 15:03:32 +00:00
|
|
|
MAPRES_SPAWNPOINT=1,
|
|
|
|
MAPRES_ITEM=2,
|
2007-08-30 07:15:26 +00:00
|
|
|
MAPRES_SPAWNPOINT_RED=3,
|
|
|
|
MAPRES_SPAWNPOINT_BLUE=4,
|
|
|
|
MAPRES_FLAGSTAND_RED=5,
|
|
|
|
MAPRES_FLAGSTAND_BLUE=6,
|
|
|
|
MAPRES_ENTS_END,
|
2007-05-22 15:03:32 +00:00
|
|
|
|
|
|
|
ITEM_NULL=0,
|
|
|
|
ITEM_WEAPON_GUN=0x00010001,
|
|
|
|
ITEM_WEAPON_SHOTGUN=0x00010002,
|
|
|
|
ITEM_WEAPON_ROCKET=0x00010003,
|
|
|
|
ITEM_WEAPON_SNIPER=0x00010004,
|
|
|
|
ITEM_WEAPON_HAMMER=0x00010005,
|
2007-07-15 13:25:10 +00:00
|
|
|
ITEM_HEALTH =0x00020001,
|
|
|
|
ITEM_ARMOR=0x00030001,
|
2007-05-22 15:03:32 +00:00
|
|
|
ITEM_NINJA=0x00040001,
|
|
|
|
};
|