Finish super team, fix bug with killing, DDraggers not finished

This commit is contained in:
btd 2010-09-21 23:09:11 +04:00
parent d195d5c7bc
commit 2af441b703
13 changed files with 83 additions and 56 deletions

View file

@ -218,7 +218,7 @@ void CCharacterCore::Tick(bool UseInput)
CCharacterCore *p = m_pWorld->m_apCharacters[i];
if(!p || p == this || !m_pTeams->SameTeam(i, m_Id))
if(!p || p == this || !m_pTeams->CanCollide(i, m_Id))
continue;
//char aBuf[512];
//str_format(aBuf, sizeof(aBuf), "ThisId = %d Id = %d TheSameTeam? = %d", ThisId, i, m_pTeams->SameTeam(i, ThisId));
@ -322,7 +322,7 @@ void CCharacterCore::Tick(bool UseInput)
continue;
//player *p = (player*)ent;
if(p == this || (m_Id != -1 && !m_pTeams->SameTeam(m_Id, i))) { // || !(p->flags&FLAG_ALIVE)
if(p == this || (m_Id != -1 && !m_pTeams->CanCollide(m_Id, i))) { // || !(p->flags&FLAG_ALIVE)
continue; // make sure that we don't nudge our self
}
// handle player <-> player collision

View file

@ -115,6 +115,14 @@ void CCharacter::SetWeapon(int W)
m_ActiveWeapon = 0;
}
bool CCharacter::CanCollide(int Cid) {
return Teams()->m_Core.CanCollide(GetPlayer()->GetCID(), Cid);
}
bool CCharacter::SameTeam(int Cid) {
return Teams()->m_Core.SameTeam(GetPlayer()->GetCID(), Cid);
}
bool CCharacter::IsGrounded()
{
if(GameServer()->Collision()->CheckPoint(m_Pos.x+m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5))
@ -314,7 +322,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 || Target->Team() != this->Team()) /*|| GameServer()->Collision()->IntersectLine(ProjStartPos, Target->m_Pos, NULL, NULL)*/)
if ((Target == this || !CanCollide(i)) /*|| GameServer()->Collision()->IntersectLine(ProjStartPos, Target->m_Pos, NULL, NULL)*/)
continue;
// set his velocity to fast upward (for now)
@ -1172,7 +1180,7 @@ void CCharacter::Die(int Killer, int Weapon)
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);
Controller->m_Teams.m_Core.Team(m_pPlayer->GetCID(), 0);
// send the kill message
CNetMsg_Sv_KillMsg Msg;

View file

@ -97,6 +97,8 @@ public:
void OnFinish();
int Team();
bool CanCollide(int Cid);
bool SameTeam(int Cid);
struct
{

View file

@ -12,77 +12,83 @@
const int LENGTH=700;
CDragger::CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW)
: CEntity(pGameWorld, NETOBJTYPE_LASER)
: CEntity(pGameWorld, NETOBJTYPE_LASER), m_Targets()
{
m_Pos = Pos;
m_Strength = Strength;
m_EvalTick = Server()->Tick();
m_NW = NW;
GameWorld()->InsertEntity(this);
}
void CDragger::Move()
{
if (m_Target)
if (m_Targets.empty())
return;
CCharacter *Ents[16];
int IdInTeam[16];
int LenInTeam[16];
for (int i = 0; i < 16; i++) {
IdInTeam[i] = -1;
LenInTeam[i] = 0;
}
int Num = -1;
Num = GameServer()->m_World.FindEntities(m_Pos,LENGTH, (CEntity**)Ents, 16, NETOBJTYPE_CHARACTER);
int Id=-1;
int MinLen=0;
for (int i = 0; i < Num; i++)
{
m_Target = Ents[i];
int Res=0;
if (!m_NW)
Res = GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Target->m_Pos, 0, 0);
else
Res = GameServer()->Collision()->IntersectNoLaserNW(m_Pos, m_Target->m_Pos, 0, 0);
CCharacter * Target = Ents[i];
int Res = m_NW ? GameServer()->Collision()->IntersectNoLaserNW(m_Pos, Target->m_Pos, 0, 0) :
GameServer()->Collision()->IntersectNoLaser(m_Pos, Target->m_Pos, 0, 0);
if (Res==0)
{
int Len=length(Ents[i]->m_Pos - m_Pos);
if (MinLen==0 || MinLen>Len)
int Len=length(Target->m_Pos - m_Pos);
if (LenInTeam[Target->Team()] == 0 || LenInTeam[Target->Team()] > Len)
{
MinLen=Len;
Id=i;
LenInTeam[Target->Team()] = Len;
IdInTeam[Target->Team()] = i;
}
}
}
if (Id!=-1)
{
m_Target = Ents[Id];
}
else
{
m_Target=0;
for (int i = 0; i < 16; i++) {
if(IdInTeam[i] != -1) {
CCharacter *Target = Ents[IdInTeam[i]];
m_Targets.push_back(Target);
}
}
}
void CDragger::Drag()
{
if (m_Target)
if (!m_Targets.empty())
{
int Res = 0;
if (!m_NW)
Res = GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Target->m_Pos, 0, 0);
else
Res = GameServer()->Collision()->IntersectNoLaserNW(m_Pos, m_Target->m_Pos, 0, 0);
if (Res || length(m_Pos-m_Target->m_Pos)>700)
/*
int Res = m_NW ? GameServer()->Collision()->IntersectNoLaserNW(m_Pos, m_Target->m_Pos, 0, 0) :
GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Target->m_Pos, 0, 0);
if (Res || length(m_Pos-m_Target->m_Pos)>700)//TODO: USE CONSTANTS IDIOT
{
m_Target=0;
m_Targets.clear();
}
else
if (length(m_Pos-m_Target->m_Pos)>28)
if(!((m_Target->m_CurrentTile >= TILE_STOPL && m_Target->m_CurrentTile <= TILE_STOPT) || (m_Target->m_CurrentFTile >= TILE_STOPL && m_Target->m_CurrentFTile <= TILE_STOPT)))
m_Target->m_Core.m_Vel+=normalize(m_Pos-m_Target->m_Pos)*m_Strength;
else {
for(std::list<CCharacter * >::iterator i = m_Targets.begin(); i != m_Targets.end(); ++i) {
CCharacter * Target = *i;
if (length(m_Pos-Target->m_Pos)>28) {
if(!((Target->m_CurrentTile >= TILE_STOPL
&& Target->m_CurrentTile <= TILE_STOPT)
|| (Target->m_CurrentFTile >= TILE_STOPL
&& Target->m_CurrentFTile <= TILE_STOPT)))
Target->m_Core.m_Vel+=normalize(m_Pos-Target->m_Pos)*m_Strength;
}
}
}*/
}
}
void CDragger::Reset()
{
m_Targets.clear();
GameServer()->m_World.DestroyEntity(this);
}
@ -107,10 +113,13 @@ void CDragger::Tick()
void CDragger::Snap(int SnappingClient)
{
if (m_Target)
/*
if (m_Targets.empty())
{
if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient,m_Target->m_Pos))
return;
for(std::list<CCharacter * >::iterator i = m_Targets.begin(); i != m_Targets.end(); ++i) {
if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient,(*i)->m_Pos))
return;
}
}
else
if(NetworkClipped(SnappingClient,m_Pos))
@ -141,6 +150,7 @@ void CDragger::Snap(int SnappingClient)
else if (StartTick>Server()->Tick())
StartTick = Server()->Tick();
obj->m_StartTick = StartTick;
*/
}
//ÿ òóò áûë
//ÿ òîæå

View file

@ -4,7 +4,7 @@
#define GAME_SERVER_ENTITY_DRAGGER_H
#include <game/server/entity.h>
#include <list>
class CCharacter;
class CDragger : public CEntity
@ -14,7 +14,7 @@ class CDragger : public CEntity
int m_EvalTick;
void Move();
void Drag();
CCharacter * m_Target;
std::list<CCharacter *> m_Targets;
bool m_NW;
public:

View file

@ -22,11 +22,10 @@ CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEner
bool CLaser::HitCharacter(vec2 From, vec2 To)
{
vec2 At;
CCharacter *OwnerChar = GameServer()->GetPlayerChar(m_Owner);//TODO: Find all and get closest non in Team
CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, m_Bounces != 0 ? 0: OwnerChar);
CCharacter *OwnerChar = GameServer()->GetPlayerChar(m_Owner);
CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, m_Bounces != 0 ? 0: OwnerChar, m_Owner);
if(!Hit)
return false;
if(OwnerChar != 0 && OwnerChar->Team() != Hit->Team()) return false;
m_From = From;
m_Pos = At;
m_Energy = -1;

View file

@ -97,8 +97,8 @@ void CProjectile::Tick()
bool isWeaponCollide = false;
if(OwnerChar && TargetChr
&& OwnerChar->m_Alive && TargetChr->m_Alive
&& OwnerChar->Team() != TargetChr->Team()) isWeaponCollide = true;
&& OwnerChar->m_Alive && TargetChr->m_Alive
&& !TargetChr->CanCollide(m_Owner)) isWeaponCollide = true;
if( ((TargetChr && (g_Config.m_SvHit || m_Owner == -1 || TargetChr == OwnerChar)) || Collide) && !isWeaponCollide)//TODO:TEAM
{

View file

@ -146,7 +146,7 @@ void CGameContext::CreateExplosion(vec2 p, int Owner, int Weapon, bool NoDamage,
if((int)Dmg)
if((g_Config.m_SvHit||NoDamage) || Owner == apEnts[i]->m_pPlayer->GetCID())
{
if(Owner != -1 && apEnts[i]->m_Alive && apEnts[i]->Team() != GetPlayerChar(Owner)->Team()) continue;
if(Owner != -1 && apEnts[i]->m_Alive && !apEnts[i]->CanCollide(Owner)) continue;
apEnts[i]->TakeDamage(ForceDir*Dmg*2, (int)Dmg, Owner, Weapon);
if(!g_Config.m_SvHit||NoDamage) break;
}

View file

@ -169,7 +169,7 @@ void CGameWorld::Tick()
// TODO: should be more general
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2& NewPos, CEntity *pNotThis)
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2& NewPos, CCharacter *pNotThis, int CollideWith)
{
// Find other players
float ClosestLen = distance(Pos0, Pos1) * 100.0f;
@ -181,7 +181,7 @@ CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, v
{
if(p == pNotThis)
continue;
if(CollideWith != -1 && !p->CanCollide(CollideWith)) continue;
vec2 IntersectPos = closest_point_on_line(Pos0, Pos1, p->m_Pos);
float Len = distance(p->m_Pos, IntersectPos);
if(Len < p->m_ProximityRadius+Radius)

View file

@ -76,7 +76,7 @@ public:
Returns:
Returns a pointer to the closest hit or NULL of there is no intersection.
*/
class CCharacter *IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, class CEntity *pNotThis = 0);
class CCharacter *IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, class CCharacter *pNotThis = 0, int CollideWith = -1);
/*
Function: closest_CCharacter

View file

@ -76,7 +76,9 @@ bool CGameTeams::SetCharacterTeam(int id, int Team) {
if(Team == TEAM_FLOCK && m_Core.Team(id) != TEAM_FLOCK) {
Character(id)->GetPlayer()->KillCharacter(WEAPON_GAME);
} else {
return false;
if(Team != TEAM_SUPER) {
return false;
}
}
}
if(m_Core.Team(id) != TEAM_FLOCK && m_Core.Team(id) != TEAM_SUPER && m_TeamState[m_Core.Team(id)] != EMPTY) {
@ -133,7 +135,7 @@ int CGameTeams::TeamMask(int Team) {
|| (Character(i)
&& Character(i)->GetPlayer()
&& Character(i)->GetPlayer()->m_ShowOthers)
) {
|| m_Core.Team(i) == TEAM_SUPER) {
Mask |= 1 << i;
}
}

View file

@ -7,7 +7,6 @@ CTeamsCore::CTeamsCore() {
}
bool CTeamsCore::SameTeam(int Cid1, int Cid2) {
if(m_Team[Cid1] == TEAM_SUPER || m_Team[Cid2] == TEAM_SUPER) return true;
return m_Team[Cid1] == m_Team[Cid2];
}
@ -17,4 +16,9 @@ int CTeamsCore::Team(int Cid) {
void CTeamsCore::Team(int Cid, int Team) {
m_Team[Cid] = Team;
}
bool CTeamsCore::CanCollide(int Cid1, int Cid2) {
if(m_Team[Cid1] == TEAM_SUPER || m_Team[Cid2] == TEAM_SUPER) return true;
return m_Team[Cid1] == m_Team[Cid2];
}

View file

@ -16,6 +16,8 @@ public:
CTeamsCore(void);
bool SameTeam(int Cid1, int Cid2);
bool CanCollide(int Cid1, int Cid2);
int Team(int Cid);
void Team(int Cid, int Team);