mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-13 03:28:19 +00:00
Fix crash with explosion. Gun hit closest character from every team
This commit is contained in:
parent
7c6b80304c
commit
3264c57306
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue