I need to think how make it better

This commit is contained in:
btd 2010-08-29 16:28:21 +04:00
parent b0d8bfca03
commit e611357dd5
8 changed files with 159 additions and 7 deletions

View file

@ -1,6 +1,5 @@
// copyright (c) 2007 magnus auvinen, see licence.txt for more info
#include "gamecore.h"
#include "server/entities/character.h"
const char *CTuningParams::m_apNames[] =
{
@ -209,7 +208,7 @@ void CCharacterCore::Tick(bool UseInput)
}
// Check against other players first
if(m_pWorld && m_pWorld->m_Tuning.m_PlayerHooking)//TODO:TEAM
if(m_pWorld && m_pWorld->m_Tuning.m_PlayerHooking)
{
float Dist = 0.0f;
for(int i = 0; i < MAX_CLIENTS; i++)

View file

@ -174,6 +174,7 @@ class CCharacterCore
{
CWorldCore *m_pWorld;
CCollision *m_pCollision;
public:
vec2 m_Pos;
vec2 m_Vel;

View file

@ -298,7 +298,7 @@ void CCharacter::FireWeapon()
m_NumObjectsHit = 0;
GameServer()->CreateSound(m_Pos, SOUND_HAMMER_FIRE);
if (!g_Config.m_SvHit) break;//TODO:TEAM
if (!g_Config.m_SvHit) break;
CCharacter *aEnts[64];
int Hits = 0;
@ -310,7 +310,7 @@ void CCharacter::FireWeapon()
CCharacter *Target = aEnts[i];
//for DDRace mod or any other mod, which needs hammer hits through the wall remove second condition
if ((Target == this) /*|| GameServer()->Collision()->IntersectLine(ProjStartPos, Target->m_Pos, NULL, NULL)*/)
if ((Target == this || Target->Team() != this->Team()) /*|| GameServer()->Collision()->IntersectLine(ProjStartPos, Target->m_Pos, NULL, NULL)*/)
continue;
// set his velocity to fast upward (for now)

View file

@ -99,8 +99,9 @@ void CProjectile::Tick()
if(m_LifeSpan > -1)
m_LifeSpan--;
if( (TargetChr && ((g_Config.m_SvHit || m_Owner == -1) || TargetChr == OwnerChar)) || Collide)//TODO:TEAM
if( (TargetChr && (g_Config.m_SvHit || m_Owner == -1 || TargetChr == OwnerChar)) || Collide)//TODO:TEAM
{
//if(OwnerChar != 0 && OwnerChar->Team() != TargetChr->Team()) return;
if(m_Explosive/*??*/ && (!TargetChr || (TargetChr && !m_Freeze)))
{
GameServer()->CreateExplosion(ColPos, m_Owner, m_Weapon, (m_Owner == -1)?true:false);

View file

@ -143,9 +143,10 @@ void CGameContext::CreateExplosion(vec2 p, int Owner, int Weapon, bool NoDamage)
ForceDir = normalize(Diff);
l = 1-clamp((l-InnerRadius)/(Radius-InnerRadius), 0.0f, 1.0f);
float Dmg = 6 * l;
if((int)Dmg)//TODO:TEAM
if((int)Dmg)
if((g_Config.m_SvHit||NoDamage) || Owner == apEnts[i]->m_pPlayer->GetCID())
{
if(apEnts[i]->Team() != GetPlayerChar(Owner)->Team()) continue;
apEnts[i]->TakeDamage(ForceDir*Dmg*2, (int)Dmg, Owner, Weapon);
if(!g_Config.m_SvHit||NoDamage) break;
}

View file

@ -3,7 +3,7 @@
#ifndef DDRACE_H
#define DDRACE_H
#include <game/server/gamecontroller.h>
#include <game/server/teams.h>
#include <game/teams.h>
class CGameControllerDDRace : public IGameController

103
src/game/teams.cpp Normal file
View file

@ -0,0 +1,103 @@
#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];
}

47
src/game/teams.h Normal file
View file

@ -0,0 +1,47 @@
#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