Continue teams

This commit is contained in:
btd 2010-08-28 17:47:52 +04:00
parent 28a668c2c8
commit fa6a79b309
4 changed files with 118 additions and 1 deletions

View file

@ -16,7 +16,7 @@ config:Finalize("config.lua")
-- data compiler
function Script(name)
if family == "windows" then
return str_replace(name, "/", "\\")
str_replace(name, "/", "\\")
end
return "python " .. name
end

View file

@ -675,6 +675,7 @@ void CCharacter::Tick()
}
if(((TileIndex1 == TILE_BEGIN) || (TileIndex2 == TILE_BEGIN)) && (m_RaceState == RACE_NONE || m_RaceState == RACE_STARTED))
{
//TODO: CTeams::OnCharacterStart();
m_StartTime = Server()->Tick();
m_RefreshTime = Server()->Tick();
m_RaceState = RACE_STARTED;
@ -682,6 +683,8 @@ void CCharacter::Tick()
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));

71
src/game/server/teams.cpp Normal file
View file

@ -0,0 +1,71 @@
#include "teams.h"
CTeams::CTeams(CGameContext* gameContext) : m_GameServer(gameContext) {
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) {
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);
Char->m_RaceState = RACE_STARTED;
Char->m_StartTime = Tick;
Char->m_RefreshTime = Tick;
}
}
}
}
void CTeams::OnCharacterFinish(int id) {
if(m_Team[id] == 0) {
//TODO: as simple DDRace results
} else {
m_TeeFinished[id] = true;
if(TeamFinished(m_Team[id])) {
//TODO: as simple DDRace results
}
}
}
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(getCharacter(id)->m_RaceState != RACE_NONE) {
return false;
}
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;
}

43
src/game/server/teams.h Normal file
View file

@ -0,0 +1,43 @@
#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;
public:
enum {
EMPTY,
OPEN,
CLOSED,
STARTED,
FINISHED
};
CTeams(CGameContext* gameContext);
//helper methods
CCharacter* getCharacter(int id) { return GameServer()->GetPlayerChar(id); }
CGameContext* GameServer() { return m_GameServer; }
IServer* Server() { return m_GameServer->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);
};
#endif