2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef GAME_GAMECORE_H
|
|
|
|
#define GAME_GAMECORE_H
|
|
|
|
|
|
|
|
#include <base/system.h>
|
|
|
|
#include <base/math.h>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include "collision.h"
|
|
|
|
#include <engine/shared/protocol.h>
|
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
|
2010-08-30 12:13:43 +00:00
|
|
|
#include "teamscore.h"
|
2010-09-29 14:45:54 +00:00
|
|
|
#include "mapitems.h"
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-01-06 03:46:10 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CTuneParam
|
|
|
|
{
|
|
|
|
int m_Value;
|
|
|
|
public:
|
|
|
|
void Set(int v) { m_Value = v; }
|
|
|
|
int Get() const { return m_Value; }
|
|
|
|
CTuneParam &operator = (int v) { m_Value = (int)(v*100.0f); return *this; }
|
|
|
|
CTuneParam &operator = (float v) { m_Value = (int)(v*100.0f); return *this; }
|
|
|
|
operator float() const { return m_Value/100.0f; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class CTuningParams
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTuningParams()
|
|
|
|
{
|
|
|
|
const float TicksPerSecond = 50.0f;
|
|
|
|
#define MACRO_TUNING_PARAM(Name,ScriptName,Value) m_##Name.Set((int)(Value*100.0f));
|
|
|
|
#include "tuning.h"
|
|
|
|
#undef MACRO_TUNING_PARAM
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *m_apNames[];
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#define MACRO_TUNING_PARAM(Name,ScriptName,Value) CTuneParam m_##Name;
|
|
|
|
#include "tuning.h"
|
|
|
|
#undef MACRO_TUNING_PARAM
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
static int Num() { return sizeof(CTuningParams)/sizeof(int); }
|
|
|
|
bool Set(int Index, float Value);
|
|
|
|
bool Set(const char *pName, float Value);
|
|
|
|
bool Get(int Index, float *pValue);
|
|
|
|
bool Get(const char *pName, float *pValue);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline vec2 GetDirection(int Angle)
|
|
|
|
{
|
|
|
|
float a = Angle/256.0f;
|
|
|
|
return vec2(cosf(a), sinf(a));
|
|
|
|
}
|
|
|
|
|
2011-02-13 06:47:51 +00:00
|
|
|
inline vec2 GetDir(float Angle)
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2011-02-13 06:47:51 +00:00
|
|
|
return vec2(cosf(Angle), sinf(Angle));
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline float GetAngle(vec2 Dir)
|
|
|
|
{
|
|
|
|
if(Dir.x == 0 && Dir.y == 0)
|
|
|
|
return 0.0f;
|
2011-02-13 06:47:51 +00:00
|
|
|
float a = atanf(Dir.y/Dir.x);
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Dir.x < 0)
|
2011-02-13 06:47:51 +00:00
|
|
|
a = a+pi;
|
|
|
|
return a;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void StrToInts(int *pInts, int Num, const char *pStr)
|
|
|
|
{
|
|
|
|
int Index = 0;
|
|
|
|
while(Num)
|
|
|
|
{
|
|
|
|
char aBuf[4] = {0,0,0,0};
|
|
|
|
for(int c = 0; c < 4 && pStr[Index]; c++, Index++)
|
|
|
|
aBuf[c] = pStr[Index];
|
|
|
|
*pInts = ((aBuf[0]+128)<<24)|((aBuf[1]+128)<<16)|((aBuf[2]+128)<<8)|(aBuf[3]+128);
|
|
|
|
pInts++;
|
|
|
|
Num--;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// null terminate
|
|
|
|
pInts[-1] &= 0xffffff00;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void IntsToStr(const int *pInts, int Num, char *pStr)
|
|
|
|
{
|
|
|
|
while(Num)
|
|
|
|
{
|
|
|
|
pStr[0] = (((*pInts)>>24)&0xff)-128;
|
|
|
|
pStr[1] = (((*pInts)>>16)&0xff)-128;
|
|
|
|
pStr[2] = (((*pInts)>>8)&0xff)-128;
|
|
|
|
pStr[3] = ((*pInts)&0xff)-128;
|
|
|
|
pStr += 4;
|
|
|
|
pInts++;
|
|
|
|
Num--;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// null terminate
|
|
|
|
pStr[-1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-13 06:47:51 +00:00
|
|
|
inline vec2 CalcPos(vec2 Pos, vec2 Velocity, float Curvature, float Speed, float Time)
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2011-02-13 06:47:51 +00:00
|
|
|
vec2 n;
|
|
|
|
Time *= Speed;
|
|
|
|
n.x = Pos.x + Velocity.x*Time;
|
|
|
|
n.y = Pos.y + Velocity.y*Time + Curvature/10000*(Time*Time);
|
|
|
|
return n;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline T SaturatedAdd(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float VelocityRamp(float Value, float Start, float Range, float Curvature);
|
|
|
|
|
|
|
|
// hooking stuff
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
HOOK_RETRACTED=-1,
|
|
|
|
HOOK_IDLE=0,
|
|
|
|
HOOK_RETRACT_START=1,
|
|
|
|
HOOK_RETRACT_END=3,
|
|
|
|
HOOK_FLYING,
|
|
|
|
HOOK_GRABBED,
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
COREEVENT_GROUND_JUMP=0x01,
|
|
|
|
COREEVENT_AIR_JUMP=0x02,
|
|
|
|
COREEVENT_HOOK_LAUNCH=0x04,
|
|
|
|
COREEVENT_HOOK_ATTACH_PLAYER=0x08,
|
|
|
|
COREEVENT_HOOK_ATTACH_GROUND=0x10,
|
|
|
|
COREEVENT_HOOK_HIT_NOHOOK=0x20,
|
|
|
|
COREEVENT_HOOK_RETRACT=0x40,
|
|
|
|
};
|
|
|
|
|
|
|
|
class CWorldCore
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CWorldCore()
|
|
|
|
{
|
|
|
|
mem_zero(m_apCharacters, sizeof(m_apCharacters));
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CTuningParams m_Tuning;
|
|
|
|
class CCharacterCore *m_apCharacters[MAX_CLIENTS];
|
|
|
|
};
|
|
|
|
|
|
|
|
class CCharacterCore
|
|
|
|
{
|
|
|
|
CWorldCore *m_pWorld;
|
|
|
|
CCollision *m_pCollision;
|
|
|
|
public:
|
|
|
|
vec2 m_Pos;
|
|
|
|
vec2 m_Vel;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 m_HookPos;
|
|
|
|
vec2 m_HookDir;
|
|
|
|
int m_HookTick;
|
|
|
|
int m_HookState;
|
|
|
|
int m_HookedPlayer;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_Jumped;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_Direction;
|
|
|
|
int m_Angle;
|
|
|
|
CNetObj_PlayerInput m_Input;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_TriggeredEvents;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore* pTeams);
|
2010-05-29 07:25:38 +00:00
|
|
|
void Reset();
|
|
|
|
void Tick(bool UseInput);
|
|
|
|
void Move();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void Read(const CNetObj_CharacterCore *pObjCore);
|
|
|
|
void Write(CNetObj_CharacterCore *pObjCore);
|
|
|
|
void Quantize();
|
2011-04-09 06:41:31 +00:00
|
|
|
|
|
|
|
// DDRace
|
|
|
|
|
|
|
|
int m_Id;
|
|
|
|
bool m_pReset;
|
|
|
|
class CCollision *Collision() { return m_pCollision; }
|
2010-09-08 16:22:11 +00:00
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
CTeamsCore* m_pTeams;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileIndex;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileFlags;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileFIndex;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileFFlags;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileSIndex;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileSFlags;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileIndexL;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileFlagsL;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileFIndexL;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileFFlagsL;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileSIndexL;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileSFlagsL;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileIndexR;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileFlagsR;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileFIndexR;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileFFlagsR;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileSIndexR;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileSFlagsR;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileIndexT;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileFlagsT;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileFIndexT;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileFFlagsT;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileSIndexT;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileSFlagsT;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileIndexB;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileFlagsB;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileFIndexB;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileFFlagsB;
|
2010-09-29 14:45:54 +00:00
|
|
|
int m_TileSIndexB;
|
2010-11-01 01:51:17 +00:00
|
|
|
int m_TileSFlagsB;
|
2010-11-13 13:22:19 +00:00
|
|
|
bool IsRightTeam(int MapIndex);
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2011-08-13 00:11:06 +00:00
|
|
|
#endif
|