mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Teams collision a works fine... But i broke collision with tiles
This commit is contained in:
parent
f46b7a58a9
commit
4544b91d2f
|
@ -445,8 +445,9 @@ static void Evolve(CNetObj_Character *pCharacter, int Tick)
|
|||
{
|
||||
CWorldCore TempWorld;
|
||||
CCharacterCore TempCore;
|
||||
CTeamsCore TempTeams;
|
||||
mem_zero(&TempCore, sizeof(TempCore));
|
||||
TempCore.Init(&TempWorld, g_GameClient.Collision());
|
||||
TempCore.Init(&TempWorld, g_GameClient.Collision(), &TempTeams);//????
|
||||
TempCore.Read(pCharacter);
|
||||
|
||||
while(pCharacter->m_Tick < Tick)
|
||||
|
@ -943,7 +944,7 @@ void CGameClient::OnPredict()
|
|||
if(!m_Snap.m_aCharacters[i].m_Active)
|
||||
continue;
|
||||
|
||||
g_GameClient.m_aClients[i].m_Predicted.Init(&World, Collision());
|
||||
g_GameClient.m_aClients[i].m_Predicted.Init(&World, Collision(), &m_Teams);
|
||||
World.m_apCharacters[i] = &g_GameClient.m_aClients[i].m_Predicted;
|
||||
g_GameClient.m_aClients[i].m_Predicted.Read(&m_Snap.m_aCharacters[i].m_Cur);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <engine/console.h>
|
||||
#include <game/layers.h>
|
||||
#include <game/gamecore.h>
|
||||
#include <game/teamscore.h>
|
||||
|
||||
#include "render.h"
|
||||
|
||||
const CColor m_PredefinedColors[MAX_CLIENTS] = {
|
||||
|
@ -61,6 +63,7 @@ class CGameClient : public IGameClient
|
|||
|
||||
CLayers m_Layers;
|
||||
class CCollision m_Collision;
|
||||
class CTeamsCore m_Teams;
|
||||
CUI m_UI;
|
||||
|
||||
void DispatchInput();
|
||||
|
|
|
@ -218,7 +218,7 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
GoingToHitGround = true;
|
||||
m_pReset = true;
|
||||
}
|
||||
|
||||
|
||||
// Check against other players first
|
||||
if(m_pWorld && m_pWorld->m_Tuning.m_PlayerHooking)
|
||||
{
|
||||
|
@ -226,9 +226,13 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
CCharacterCore *p = m_pWorld->m_apCharacters[i];
|
||||
|
||||
|
||||
if(!p || p == this || !m_pTeams->SameTeam(i, ThisId))
|
||||
continue;
|
||||
|
||||
//char aBuf[512];
|
||||
//str_format(aBuf, sizeof(aBuf), "ThisId = %d Id = %d TheSameTeam? = %d", ThisId, i, m_pTeams->SameTeam(i, ThisId));
|
||||
//dbg_msg("GameCore", aBuf);
|
||||
vec2 ClosestPoint = closest_point_on_line(m_HookPos, NewPos, p->m_Pos);
|
||||
if(distance(p->m_Pos, ClosestPoint) < PhysSize+2.0f)
|
||||
{
|
||||
|
@ -328,13 +332,13 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
continue;
|
||||
|
||||
//player *p = (player*)ent;
|
||||
if(p == this) { // || !(p->flags&FLAG_ALIVE)
|
||||
if(p == this || (ThisId != -1 && !m_pTeams->SameTeam(ThisId, i))) { // || !(p->flags&FLAG_ALIVE)
|
||||
continue; // make sure that we don't nudge our self
|
||||
}
|
||||
// handle player <-> player collision
|
||||
float d = distance(m_Pos, p->m_Pos);
|
||||
vec2 Dir = normalize(m_Pos - p->m_Pos);
|
||||
if (m_pWorld->m_Tuning.m_PlayerCollision && ThisId != -1 && m_pTeams->SameTeam(ThisId, i)) {
|
||||
if (m_pWorld->m_Tuning.m_PlayerCollision) {
|
||||
|
||||
if(d < PhysSize*1.25f && d > 1.0f)
|
||||
{
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
#include "teams.h"
|
||||
|
||||
|
||||
CTeams::CTeams(CGameContext *pGameContext) : m_pGameContext(pGameContext) {
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
m_Team[i] = 0;
|
||||
m_TeamState[i] = EMPTY;
|
||||
m_TeeFinished[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CTeams::OnCharacterStart(int id) {
|
||||
int Tick = Server()->Tick();
|
||||
if(m_Team[id] == 0) {
|
||||
CCharacter* Char = Character(id);
|
||||
Char->m_RaceState = RACE_STARTED;
|
||||
Char->m_StartTime = Tick;
|
||||
Char->m_RefreshTime = Tick;
|
||||
} else {
|
||||
if(m_TeamState[m_Team[id]] <= CLOSED) {
|
||||
ChangeTeamState(m_Team[id], STARTED);
|
||||
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
if(m_Team[i] == m_Team[id]) {
|
||||
CCharacter* Char = Character(i);
|
||||
|
||||
Char->m_RaceState = RACE_STARTED;
|
||||
Char->m_StartTime = Tick;
|
||||
Char->m_RefreshTime = Tick;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CTeams::OnCharacterFinish(int id) {
|
||||
if(m_Team[id] == 0) {
|
||||
Character(id)->OnFinish();
|
||||
} else {
|
||||
m_TeeFinished[id] = true;
|
||||
if(TeamFinished(m_Team[id])) {
|
||||
ChangeTeamState(m_Team[id], FINISHED);//TODO: Make it better
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
if(SameTeam(i, id)) {
|
||||
CCharacter * Char = Character(i);
|
||||
if(Char != 0) {
|
||||
Char->OnFinish();
|
||||
m_TeeFinished[i] = false;
|
||||
} //else {
|
||||
// m_Team[id] = 0; //i saw zomby =)
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CTeams::SetCharacterTeam(int id, int Team) {
|
||||
//TODO: Send error message
|
||||
if(id < 0 || id >= MAX_CLIENTS || Team < 0 || Team >= MAX_CLIENTS) {
|
||||
return false;
|
||||
}
|
||||
if(m_TeamState[Team] >= CLOSED) {
|
||||
return false;
|
||||
}
|
||||
if(m_Team[id] != 0 && m_TeamState[m_Team[id]] != EMPTY) {
|
||||
bool NoOneInOldTeam = true;
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
if(SameTeam(i, id)) {
|
||||
NoOneInOldTeam = false;//all good exists someone in old team
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(NoOneInOldTeam) {
|
||||
m_TeamState[m_Team[id]] = EMPTY;
|
||||
}
|
||||
}
|
||||
m_Team[id] = Team;
|
||||
if(m_TeamState[Team] == EMPTY) {
|
||||
ChangeTeamState(Team, OPEN);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CTeams::ChangeTeamState(int Team, int State) {
|
||||
m_TeamState[Team] = State;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CTeams::TeamFinished(int Team) {
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
if(m_Team[i] == Team && !m_TeeFinished[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTeams::SameTeam(int Cid1, int Cid2) {
|
||||
return m_Team[Cid1] = m_Team[Cid2];
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
#ifndef GAME_SERVER_TEAMS_H
|
||||
#define GAME_SERVER_TEAMS_H
|
||||
|
||||
#include <game/server/entities/character.h>
|
||||
#include <game/server/gamecontext.h>
|
||||
|
||||
class CTeams {
|
||||
int m_Team[MAX_CLIENTS];
|
||||
int m_TeamState[MAX_CLIENTS];
|
||||
bool m_TeeFinished[MAX_CLIENTS];
|
||||
|
||||
class CGameContext * m_pGameContext;
|
||||
|
||||
public:
|
||||
enum {
|
||||
EMPTY,
|
||||
OPEN,
|
||||
CLOSED,
|
||||
STARTED,
|
||||
FINISHED
|
||||
};
|
||||
|
||||
CTeams(CGameContext *pGameContext);
|
||||
|
||||
//helper methods
|
||||
CCharacter* Character(int id) { return GameServer()->GetPlayerChar(id); }
|
||||
|
||||
class CGameContext *GameServer() { return m_pGameContext; }
|
||||
class IServer *Server() { return m_pGameContext->Server(); }
|
||||
|
||||
void OnCharacterStart(int id);
|
||||
void OnCharacterFinish(int id);
|
||||
|
||||
bool SetCharacterTeam(int id, int Team);
|
||||
|
||||
void ChangeTeamState(int Team, int State);
|
||||
|
||||
bool TeamFinished(int Team);
|
||||
|
||||
bool SameTeam(int Cid1, int Cid2);
|
||||
|
||||
int GetTeam(int Cid) {
|
||||
return m_Team[Cid];
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -7,7 +7,7 @@ CTeamsCore::CTeamsCore() {
|
|||
}
|
||||
|
||||
bool CTeamsCore::SameTeam(int Cid1, int Cid2) {
|
||||
return m_Team[Cid1] = m_Team[Cid2];
|
||||
return m_Team[Cid1] == m_Team[Cid2];
|
||||
}
|
||||
|
||||
int CTeamsCore::Team(int Cid) {
|
||||
|
|
Loading…
Reference in a new issue