Fix crash with explosion. Gun hit closest character from every team

This commit is contained in:
btd 2010-08-31 21:14:33 +04:00
parent 7c6b80304c
commit 3264c57306
2 changed files with 28 additions and 15 deletions

View file

@ -28,10 +28,16 @@ CGun::CGun(CGameWorld *pGameWorld, vec2 Pos, bool Freeze, bool Explosive)
void CGun::Fire() void CGun::Fire()
{ {
CCharacter *Ents[16]; 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; int Num = -1;
Num = GameServer()->m_World.FindEntities(m_Pos,RANGE, (CEntity**)Ents, 16, NETOBJTYPE_CHARACTER); Num = GameServer()->m_World.FindEntities(m_Pos,RANGE, (CEntity**)Ents, 16, NETOBJTYPE_CHARACTER);
int Id=-1;
int MinLen=0;
for (int i = 0; i < Num; i++) for (int i = 0; i < Num; i++)
{ {
CCharacter *Target = Ents[i]; CCharacter *Target = Ents[i];
@ -40,24 +46,31 @@ void CGun::Fire()
res = GameServer()->Collision()->IntersectLine(m_Pos, Target->m_Pos,0,0,false); res = GameServer()->Collision()->IntersectLine(m_Pos, Target->m_Pos,0,0,false);
if (!res) if (!res)
{ {
int Len=length(Ents[i]->m_Pos - m_Pos); int Len=length(Target->m_Pos - m_Pos);
if (MinLen==0) if (LenInTeam[Target->Team()] == 0)
{ {
MinLen=Len; LenInTeam[Target->Team()] = Len;
Id=i; IdInTeam[Target->Team()] = i;
} }
else if(MinLen>Len) else if(LenInTeam[Target->Team()] > Len)
{ {
MinLen=Len; LenInTeam[Target->Team()] = Len;
Id=i; IdInTeam[Target->Team()] = i;
} }
} }
} }
if (Id!=-1) //if (Id!=-1)
{ //{
CCharacter *Target = Ents[Id]; // CCharacter *Target = Ents[Id];
vec2 Fdir = normalize(Target->m_Pos - m_Pos); // vec2 Fdir = normalize(Target->m_Pos - m_Pos);
new CPlasma(&GameServer()->m_World, m_Pos, Fdir, m_Freeze, m_Explosive); // new CPlasma(&GameServer()->m_World, m_Pos, Fdir, m_Freeze, m_Explosive);
//}
for (int i = 0; i < 16; i++) {
if(IdInTeam[i] != -1) {
CCharacter *Target = Ents[IdInTeam[i]];
vec2 Fdir = normalize(Target->m_Pos - m_Pos);
new CPlasma(&GameServer()->m_World, m_Pos, Fdir, m_Freeze, m_Explosive);
}
} }
} }

View file

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