mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 18:18:18 +00:00
Logic and scores seems done. Next will be collision
This commit is contained in:
parent
fa6a79b309
commit
366e175983
|
@ -551,8 +551,89 @@ void CCharacter::OnDirectInput(CNetObj_PlayerInput *pNewInput)
|
|||
mem_copy(&m_LatestPrevInput, &m_LatestInput, sizeof(m_LatestInput));
|
||||
}
|
||||
|
||||
void CCharacter::OnFinish() {
|
||||
//TODO: this ugly
|
||||
float time = (float)(Server()->Tick() - m_StartTime) / ((float)Server()->TickSpeed());
|
||||
CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCID());
|
||||
char aBuf[128];
|
||||
m_CpActive=-2;
|
||||
str_format(aBuf, sizeof(aBuf), "%s finished in: %d minute(s) %5.2f second(s)", Server()->ClientName(m_pPlayer->GetCID()), (int)time/60, time-((int)time/60*60));
|
||||
if(!g_Config.m_SvHideScore)
|
||||
GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
|
||||
else
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
|
||||
|
||||
if(time - pData->m_BestTime < 0)
|
||||
{
|
||||
// new record \o/
|
||||
str_format(aBuf, sizeof(aBuf), "New record: %5.2f second(s) better", time - pData->m_BestTime);
|
||||
if(!g_Config.m_SvHideScore)
|
||||
GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
|
||||
else
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
|
||||
}
|
||||
|
||||
if(!pData->m_BestTime || time < pData->m_BestTime)
|
||||
{
|
||||
// update the score
|
||||
pData->Set(time, m_CpCurrent);
|
||||
|
||||
if(str_comp_num(Server()->ClientName(m_pPlayer->GetCID()), "nameless tee", 12) != 0)
|
||||
GameServer()->Score()->SaveScore(m_pPlayer->GetCID(), time, this);
|
||||
}
|
||||
|
||||
// update server best time
|
||||
if(GameServer()->m_pController->m_CurrentRecord == 0 || time < GameServer()->m_pController->m_CurrentRecord)
|
||||
{
|
||||
// check for nameless
|
||||
if(str_comp_num(Server()->ClientName(m_pPlayer->GetCID()), "nameless tee", 12) != 0) {
|
||||
GameServer()->m_pController->m_CurrentRecord = time;
|
||||
//dbg_msg("character", "Finish");
|
||||
// GetPlayer()->SendServerRecord();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
m_RaceState = RACE_NONE;
|
||||
// set player score
|
||||
if(!GameServer()->Score()->PlayerData(m_pPlayer->GetCID())->m_CurrentTime || GameServer()->Score()->PlayerData(m_pPlayer->GetCID())->m_CurrentTime > time)
|
||||
{
|
||||
GameServer()->Score()->PlayerData(m_pPlayer->GetCID())->m_CurrentTime = time;
|
||||
|
||||
// send it to all players
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->m_IsUsingRaceClient)
|
||||
{
|
||||
if(g_Config.m_SvHideScore || i == m_pPlayer->GetCID())
|
||||
{
|
||||
CNetMsg_Sv_PlayerTime Msg;
|
||||
char aBuf[16];
|
||||
str_format(aBuf, sizeof(aBuf), "%.0f", time*100.0f); // damn ugly but the only way i know to do it
|
||||
int TimeToSend;
|
||||
sscanf(aBuf, "%d", &TimeToSend);
|
||||
Msg.m_Time = TimeToSend;
|
||||
Msg.m_Cid = m_pPlayer->GetCID();
|
||||
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int TTime = 0-(int)time;
|
||||
if(m_pPlayer->m_Score < TTime)
|
||||
m_pPlayer->m_Score = TTime;
|
||||
|
||||
}
|
||||
|
||||
int CCharacter::Team() {
|
||||
CGameControllerDDRace* Controller = (CGameControllerDDRace*)GameServer()->m_pController;
|
||||
return Controller->m_Teams.GetTeam(m_pPlayer->GetCID());
|
||||
}
|
||||
|
||||
void CCharacter::Tick()
|
||||
{
|
||||
CGameControllerDDRace* Controller = (CGameControllerDDRace*)GameServer()->m_pController;
|
||||
int MapIndex = GameServer()->Collision()->GetMapIndex(m_PrevPos, m_Pos);
|
||||
int TileIndex1 = GameServer()->Collision()->GetCollisionDDRace(MapIndex);
|
||||
int TileIndex2 = GameServer()->Collision()->GetFCollisionDDRace(MapIndex);
|
||||
|
@ -560,7 +641,7 @@ void CCharacter::Tick()
|
|||
if(m_pPlayer->m_ForceBalanced)
|
||||
{
|
||||
char Buf[128];
|
||||
str_format(Buf, sizeof(Buf), "You were moved to %s due to team balancing", GameServer()->m_pController->GetTeamName(m_pPlayer->GetTeam()));
|
||||
str_format(Buf, sizeof(Buf), "You were moved to %s due to team balancing", Controller->GetTeamName(m_pPlayer->GetTeam()));
|
||||
GameServer()->SendBroadcast(Buf, m_pPlayer->GetCID());
|
||||
|
||||
m_pPlayer->m_ForceBalanced = false;
|
||||
|
@ -673,87 +754,14 @@ void CCharacter::Tick()
|
|||
m_CpCurrent[cp] = time;
|
||||
m_CpTick = Server()->Tick() + Server()->TickSpeed()*2;
|
||||
}
|
||||
if(((TileIndex1 == TILE_BEGIN) || (TileIndex2 == TILE_BEGIN)) && (m_RaceState == RACE_NONE || m_RaceState == RACE_STARTED))
|
||||
if(((TileIndex1 == TILE_BEGIN) || (TileIndex2 == TILE_BEGIN)) && m_RaceState == RACE_NONE)
|
||||
{
|
||||
//TODO: CTeams::OnCharacterStart();
|
||||
m_StartTime = Server()->Tick();
|
||||
m_RefreshTime = Server()->Tick();
|
||||
m_RaceState = RACE_STARTED;
|
||||
Controller->m_Teams.OnCharacterStart(m_pPlayer->GetCID());
|
||||
}
|
||||
|
||||
if(((TileIndex1 == TILE_END) || (TileIndex2 == TILE_END)) && m_RaceState == RACE_STARTED)
|
||||
{
|
||||
//TODO: CTeams::OnCharacterFinish()
|
||||
//TODO2: make method for finishing
|
||||
char aBuf[128];
|
||||
m_CpActive=-2;
|
||||
str_format(aBuf, sizeof(aBuf), "%s finished in: %d minute(s) %5.2f second(s)", Server()->ClientName(m_pPlayer->GetCID()), (int)time/60, time-((int)time/60*60));
|
||||
if(!g_Config.m_SvHideScore)
|
||||
GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
|
||||
else
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
|
||||
|
||||
if(time - pData->m_BestTime < 0)
|
||||
{
|
||||
// new record \o/
|
||||
str_format(aBuf, sizeof(aBuf), "New record: %5.2f second(s) better", time - pData->m_BestTime);
|
||||
if(!g_Config.m_SvHideScore)
|
||||
GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
|
||||
else
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
|
||||
}
|
||||
|
||||
if(!pData->m_BestTime || time < pData->m_BestTime)
|
||||
{
|
||||
// update the score
|
||||
pData->Set(time, m_CpCurrent);
|
||||
|
||||
if(str_comp_num(Server()->ClientName(m_pPlayer->GetCID()), "nameless tee", 12) != 0)
|
||||
GameServer()->Score()->SaveScore(m_pPlayer->GetCID(), time, this);
|
||||
}
|
||||
|
||||
// update server best time
|
||||
if(GameServer()->m_pController->m_CurrentRecord == 0 || time < GameServer()->m_pController->m_CurrentRecord)
|
||||
{
|
||||
// check for nameless
|
||||
if(str_comp_num(Server()->ClientName(m_pPlayer->GetCID()), "nameless tee", 12) != 0) {
|
||||
GameServer()->m_pController->m_CurrentRecord = time;
|
||||
//dbg_msg("character", "Finish");
|
||||
// GetPlayer()->SendServerRecord();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
m_RaceState = RACE_NONE;
|
||||
// set player score
|
||||
if(!GameServer()->Score()->PlayerData(m_pPlayer->GetCID())->m_CurrentTime || GameServer()->Score()->PlayerData(m_pPlayer->GetCID())->m_CurrentTime > time)
|
||||
{
|
||||
GameServer()->Score()->PlayerData(m_pPlayer->GetCID())->m_CurrentTime = time;
|
||||
|
||||
// send it to all players
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->m_IsUsingRaceClient)
|
||||
{
|
||||
if(g_Config.m_SvHideScore || i == m_pPlayer->GetCID())
|
||||
{
|
||||
CNetMsg_Sv_PlayerTime Msg;
|
||||
char aBuf[16];
|
||||
str_format(aBuf, sizeof(aBuf), "%.0f", time*100.0f); // damn ugly but the only way i know to do it
|
||||
int TimeToSend;
|
||||
sscanf(aBuf, "%d", &TimeToSend);
|
||||
Msg.m_Time = TimeToSend;
|
||||
Msg.m_Cid = m_pPlayer->GetCID();
|
||||
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int TTime = 0-(int)time;
|
||||
if(m_pPlayer->m_Score < TTime)
|
||||
m_pPlayer->m_Score = TTime;
|
||||
|
||||
Controller->m_Teams.OnCharacterFinish(m_pPlayer->GetCID());
|
||||
}
|
||||
if(((TileIndex1 == TILE_FREEZE) || (TileIndex2 == TILE_FREEZE)) && !m_Super)
|
||||
{
|
||||
|
@ -1156,13 +1164,15 @@ bool CCharacter::IncreaseArmor(int Amount)
|
|||
void CCharacter::Die(int Killer, int Weapon)
|
||||
{
|
||||
int ModeSpecial = GameServer()->m_pController->OnCharacterDeath(this, GameServer()->m_apPlayers[Killer], Weapon);
|
||||
|
||||
CGameControllerDDRace* Controller = (CGameControllerDDRace*)GameServer()->m_pController;
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d",
|
||||
Killer, Server()->ClientName(Killer),
|
||||
m_pPlayer->GetCID(), Server()->ClientName(m_pPlayer->GetCID()), Weapon, ModeSpecial);
|
||||
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
|
||||
|
||||
Controller->m_Teams.SetCharacterTeam(m_pPlayer->GetCID(), 0);
|
||||
|
||||
// send the kill message
|
||||
CNetMsg_Sv_KillMsg Msg;
|
||||
Msg.m_Killer = Killer;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <game/server/entity.h>
|
||||
#include <game/generated/server_data.h>
|
||||
#include <game/generated/protocol.h>
|
||||
|
||||
#include <game/gamecore.h>
|
||||
|
||||
enum
|
||||
|
@ -92,6 +91,9 @@ public:
|
|||
|
||||
int m_RaceState;
|
||||
|
||||
void OnFinish();
|
||||
int Team();
|
||||
|
||||
struct
|
||||
{
|
||||
vec2 m_ActivationDir;
|
||||
|
|
|
@ -748,6 +748,25 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
|
|||
pChr->m_BroadTime=true;
|
||||
}
|
||||
}
|
||||
else if(!str_comp_num(pMsg->m_pMessage, "/team", 5))
|
||||
{
|
||||
int Num;
|
||||
|
||||
if(sscanf(pMsg->m_pMessage, "/team %d", &Num) == 1) {
|
||||
if(((CGameControllerDDRace*)m_pController)->m_Teams.SetCharacterTeam(p->GetCID(), Num)) {
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "%s joined to Team %d", Server()->ClientName(p->GetCID()), Num);
|
||||
SendChat(-1, CGameContext::CHAT_ALL, aBuf);
|
||||
} else {
|
||||
SendChatTarget(ClientId, "You cannot join to this team");
|
||||
}
|
||||
} else {
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "You are in team %d", p->GetCharacter()->Team());
|
||||
SendChatTarget(ClientId, aBuf);
|
||||
}
|
||||
|
||||
}
|
||||
else if (!str_comp_nocase(pMsg->m_pMessage, "/broadcast")&&g_Config.m_SvEmotionalTees)
|
||||
{
|
||||
CCharacter* pChr = p->GetCharacter();
|
||||
|
@ -1915,6 +1934,7 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
|||
//world = new GAMEWORLD;
|
||||
//players = new CPlayer[MAX_CLIENTS];
|
||||
|
||||
//TODO: No need any more?
|
||||
char buf[512];
|
||||
str_format(buf, sizeof(buf), "data/maps/%s.cfg", g_Config.m_SvMap); //
|
||||
Console()->ExecuteFile(buf);
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
#include <engine/shared/config.h>
|
||||
#include <game/mapitems.h>
|
||||
|
||||
|
||||
#include <game/generated/protocol.h>
|
||||
|
||||
#include "entities/pickup.h"
|
||||
|
||||
#include "gamecontroller.h"
|
||||
#include "gamecontext.h"
|
||||
|
||||
#include "entities/pickup.h"
|
||||
#include "entities/light.h"
|
||||
#include "entities/dragger.h"
|
||||
#include "entities/gun.h"
|
||||
|
@ -44,10 +46,12 @@ IGameController::IGameController(class CGameContext *pGameServer)
|
|||
m_aNumSpawnPoints[2] = 0;
|
||||
|
||||
m_CurrentRecord = 0;
|
||||
|
||||
}
|
||||
|
||||
IGameController::~IGameController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float IGameController::EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos)
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#define GAME_SERVER_GAMECONTROLLER_H
|
||||
|
||||
#include <base/vmath.h>
|
||||
//#include <game/server/teams.h>
|
||||
|
||||
class CDoor;
|
||||
|
||||
/*
|
||||
Class: Game Controller
|
||||
Controls the main game logic. Keeping track of team and player score,
|
||||
|
@ -71,6 +71,8 @@ public:
|
|||
IGameController(class CGameContext *pGameServer);
|
||||
virtual ~IGameController();
|
||||
|
||||
|
||||
|
||||
//void DoTeamScoreWincheck();
|
||||
//void DoPlayerScoreWincheck();
|
||||
void DoWarmup(int Seconds);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <game/server/gamecontext.h>
|
||||
#include "DDRace.h"
|
||||
|
||||
CGameControllerDDRace::CGameControllerDDRace(class CGameContext *pGameServer) : IGameController(pGameServer)
|
||||
CGameControllerDDRace::CGameControllerDDRace(class CGameContext *pGameServer) : IGameController(pGameServer), m_Teams(pGameServer)
|
||||
{
|
||||
m_pGameType = "DDRace";
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
#ifndef DDRACE_H
|
||||
#define DDRACE_H
|
||||
#include <game/server/gamecontroller.h>
|
||||
#include <game/server/score.h>
|
||||
#include <game/server/teams.h>
|
||||
|
||||
|
||||
class CGameControllerDDRace : public IGameController
|
||||
{
|
||||
|
@ -12,6 +13,8 @@ public:
|
|||
CGameControllerDDRace(class CGameContext *pGameServer);
|
||||
~CGameControllerDDRace();
|
||||
|
||||
CTeams m_Teams;
|
||||
|
||||
vec2 *m_pTeleporter;
|
||||
|
||||
void InitTeleporter();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "teams.h"
|
||||
|
||||
|
||||
CTeams::CTeams(CGameContext* gameContext) : m_GameServer(gameContext) {
|
||||
CTeams::CTeams(CGameContext *pGameContext) : m_pGameContext(pGameContext) {
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
m_Team[i] = 0;
|
||||
m_TeamState[i] = EMPTY;
|
||||
|
@ -10,16 +10,24 @@ CTeams::CTeams(CGameContext* gameContext) : m_GameServer(gameContext) {
|
|||
}
|
||||
|
||||
void CTeams::OnCharacterStart(int id) {
|
||||
if(m_TeamState[m_Team[id]] <= CLOSED) {
|
||||
ChangeTeamState(m_Team[id], STARTED);
|
||||
int Tick = Server()->Tick();
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
if(m_Team[i] == m_Team[id]) {
|
||||
CCharacter* Char = getCharacter(i);
|
||||
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;
|
||||
Char->m_RaceState = RACE_STARTED;
|
||||
Char->m_StartTime = Tick;
|
||||
Char->m_RefreshTime = Tick;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +35,23 @@ void CTeams::OnCharacterStart(int id) {
|
|||
|
||||
void CTeams::OnCharacterFinish(int id) {
|
||||
if(m_Team[id] == 0) {
|
||||
//TODO: as simple DDRace results
|
||||
Character(id)->OnFinish();
|
||||
} else {
|
||||
m_TeeFinished[id] = true;
|
||||
if(TeamFinished(m_Team[id])) {
|
||||
//TODO: as simple DDRace results
|
||||
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 =)
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,8 +64,17 @@ bool CTeams::SetCharacterTeam(int id, int Team) {
|
|||
if(m_TeamState[Team] >= CLOSED) {
|
||||
return false;
|
||||
}
|
||||
if(getCharacter(id)->m_RaceState != RACE_NONE) {
|
||||
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) {
|
||||
|
@ -69,3 +98,6 @@ bool CTeams::TeamFinished(int Team) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CTeams::SameTeam(int Cid1, int Cid2) {
|
||||
return m_Team[Cid1] = m_Team[Cid2];
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
#ifndef GAME_SERVER_TEAMS_H
|
||||
#define GAME_SERVER_TEAMS_H
|
||||
|
||||
|
||||
#include <game/server/entities/character.h>
|
||||
#include <engine/server/server.h>
|
||||
#include <game/server/gamecontext.h>
|
||||
|
||||
|
||||
class CTeams {
|
||||
int m_Team[MAX_CLIENTS];
|
||||
int m_TeamState[MAX_CLIENTS];
|
||||
bool m_TeeFinished[MAX_CLIENTS];
|
||||
CGameContext* m_GameServer;
|
||||
|
||||
class CGameContext * m_pGameContext;
|
||||
|
||||
public:
|
||||
enum {
|
||||
|
@ -22,12 +20,13 @@ public:
|
|||
FINISHED
|
||||
};
|
||||
|
||||
CTeams(CGameContext* gameContext);
|
||||
CTeams(CGameContext *pGameContext);
|
||||
|
||||
//helper methods
|
||||
CCharacter* getCharacter(int id) { return GameServer()->GetPlayerChar(id); }
|
||||
CGameContext* GameServer() { return m_GameServer; }
|
||||
IServer* Server() { return m_GameServer->Server(); }
|
||||
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);
|
||||
|
@ -38,6 +37,11 @@ public:
|
|||
|
||||
bool TeamFinished(int Team);
|
||||
|
||||
bool SameTeam(int Cid1, int Cid2);
|
||||
|
||||
int GetTeam(int Cid) {
|
||||
return m_Team[Cid];
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue