Server: Use the tuning params via GameWorld (like in prediction)

The world tuning is a part of the world. This way the entities implementation
use the same API as available on the client side.

This change is a step toward unified/shared world logic for client and server.
This commit is contained in:
Alexander Akulich 2023-09-06 02:08:01 +03:00
parent 77fc14f251
commit f58eef45b9
8 changed files with 56 additions and 46 deletions

View file

@ -182,11 +182,6 @@ void CGameWorld::RemoveEntities()
}
}
bool distCompare(std::pair<float, int> a, std::pair<float, int> b)
{
return (a.first < b.first);
}
void CGameWorld::Tick()
{
// update all objects

View file

@ -206,9 +206,9 @@ void CCharacter::HandleJetpack()
{
float Strength;
if(!m_TuneZone)
Strength = GameServer()->Tuning()->m_JetpackStrength;
Strength = Tuning()->m_JetpackStrength;
else
Strength = GameServer()->TuningList()[m_TuneZone].m_JetpackStrength;
Strength = TuningList()[m_TuneZone].m_JetpackStrength;
TakeDamage(Direction * -1.0f * (Strength / 100.0f / 6.11f), 0, m_pPlayer->GetCID(), m_Core.m_ActiveWeapon);
}
}
@ -255,9 +255,9 @@ void CCharacter::HandleNinja()
vec2 GroundElasticity;
if(!m_TuneZone)
GroundElasticity = vec2(GameServer()->Tuning()->m_GroundElasticityX, GameServer()->Tuning()->m_GroundElasticityY);
GroundElasticity = vec2(Tuning()->m_GroundElasticityX, Tuning()->m_GroundElasticityY);
else
GroundElasticity = vec2(GameServer()->TuningList()[m_TuneZone].m_GroundElasticityX, GameServer()->TuningList()[m_TuneZone].m_GroundElasticityY);
GroundElasticity = vec2(TuningList()[m_TuneZone].m_GroundElasticityX, TuningList()[m_TuneZone].m_GroundElasticityY);
Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(GetProximityRadius(), GetProximityRadius()), GroundElasticity);
@ -470,9 +470,9 @@ void CCharacter::FireWeapon()
float Strength;
if(!m_TuneZone)
Strength = GameServer()->Tuning()->m_HammerStrength;
Strength = Tuning()->m_HammerStrength;
else
Strength = GameServer()->TuningList()[m_TuneZone].m_HammerStrength;
Strength = TuningList()[m_TuneZone].m_HammerStrength;
vec2 Temp = pTarget->m_Core.m_Vel + normalize(Dir + vec2(0.f, -1.1f)) * 10.0f;
Temp = ClampVel(pTarget->m_MoveRestrictions, Temp);
@ -494,9 +494,9 @@ void CCharacter::FireWeapon()
{
float FireDelay;
if(!m_TuneZone)
FireDelay = GameServer()->Tuning()->m_HammerHitFireDelay;
FireDelay = Tuning()->m_HammerHitFireDelay;
else
FireDelay = GameServer()->TuningList()[m_TuneZone].m_HammerHitFireDelay;
FireDelay = TuningList()[m_TuneZone].m_HammerHitFireDelay;
m_ReloadTimer = FireDelay * Server()->TickSpeed() / 1000;
}
}
@ -508,9 +508,9 @@ void CCharacter::FireWeapon()
{
int Lifetime;
if(!m_TuneZone)
Lifetime = (int)(Server()->TickSpeed() * GameServer()->Tuning()->m_GunLifetime);
Lifetime = (int)(Server()->TickSpeed() * Tuning()->m_GunLifetime);
else
Lifetime = (int)(Server()->TickSpeed() * GameServer()->TuningList()[m_TuneZone].m_GunLifetime);
Lifetime = (int)(Server()->TickSpeed() * TuningList()[m_TuneZone].m_GunLifetime);
new CProjectile(
GameWorld(),
@ -534,9 +534,9 @@ void CCharacter::FireWeapon()
{
float LaserReach;
if(!m_TuneZone)
LaserReach = GameServer()->Tuning()->m_LaserReach;
LaserReach = Tuning()->m_LaserReach;
else
LaserReach = GameServer()->TuningList()[m_TuneZone].m_LaserReach;
LaserReach = TuningList()[m_TuneZone].m_LaserReach;
new CLaser(&GameServer()->m_World, m_Pos, Direction, LaserReach, m_pPlayer->GetCID(), WEAPON_SHOTGUN);
GameServer()->CreateSound(m_Pos, SOUND_SHOTGUN_FIRE, TeamMask());
@ -547,9 +547,9 @@ void CCharacter::FireWeapon()
{
int Lifetime;
if(!m_TuneZone)
Lifetime = (int)(Server()->TickSpeed() * GameServer()->Tuning()->m_GrenadeLifetime);
Lifetime = (int)(Server()->TickSpeed() * Tuning()->m_GrenadeLifetime);
else
Lifetime = (int)(Server()->TickSpeed() * GameServer()->TuningList()[m_TuneZone].m_GrenadeLifetime);
Lifetime = (int)(Server()->TickSpeed() * TuningList()[m_TuneZone].m_GrenadeLifetime);
new CProjectile(
GameWorld(),
@ -572,9 +572,9 @@ void CCharacter::FireWeapon()
{
float LaserReach;
if(!m_TuneZone)
LaserReach = GameServer()->Tuning()->m_LaserReach;
LaserReach = Tuning()->m_LaserReach;
else
LaserReach = GameServer()->TuningList()[m_TuneZone].m_LaserReach;
LaserReach = TuningList()[m_TuneZone].m_LaserReach;
new CLaser(GameWorld(), m_Pos, Direction, LaserReach, m_pPlayer->GetCID(), WEAPON_LASER);
GameServer()->CreateSound(m_Pos, SOUND_LASER_FIRE, TeamMask());
@ -601,9 +601,9 @@ void CCharacter::FireWeapon()
{
float FireDelay;
if(!m_TuneZone)
GameServer()->Tuning()->Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
Tuning()->Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
else
GameServer()->TuningList()[m_TuneZone].Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
TuningList()[m_TuneZone].Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
m_ReloadTimer = FireDelay * Server()->TickSpeed() / 1000;
}
}
@ -1184,9 +1184,9 @@ void CCharacter::Snap(int SnappingClient)
pDDNetCharacter->m_Flags |= CHARACTERFLAG_SUPER;
if(m_Core.m_EndlessHook)
pDDNetCharacter->m_Flags |= CHARACTERFLAG_ENDLESS_HOOK;
if(m_Core.m_CollisionDisabled || !GameServer()->Tuning()->m_PlayerCollision)
if(m_Core.m_CollisionDisabled || !Tuning()->m_PlayerCollision)
pDDNetCharacter->m_Flags |= CHARACTERFLAG_COLLISION_DISABLED;
if(m_Core.m_HookHitDisabled || !GameServer()->Tuning()->m_PlayerHooking)
if(m_Core.m_HookHitDisabled || !Tuning()->m_PlayerHooking)
pDDNetCharacter->m_Flags |= CHARACTERFLAG_HOOK_HIT_DISABLED;
if(m_Core.m_EndlessJump)
pDDNetCharacter->m_Flags |= CHARACTERFLAG_ENDLESS_JUMP;
@ -1915,9 +1915,9 @@ void CCharacter::HandleTuneLayer()
m_TuneZone = Collision()->IsTune(CurrentIndex);
if(m_TuneZone)
m_Core.m_Tuning = GameServer()->TuningList()[m_TuneZone]; // throw tunings from specific zone into gamecore
m_Core.m_Tuning = TuningList()[m_TuneZone]; // throw tunings from specific zone into gamecore
else
m_Core.m_Tuning = *GameServer()->Tuning();
m_Core.m_Tuning = *Tuning();
if(m_TuneZone != m_TuneZoneOld) // don't send tunigs all the time
{

View file

@ -58,9 +58,9 @@ bool CLaser::HitCharacter(vec2 From, vec2 To)
float Strength;
if(!m_TuneZone)
Strength = GameServer()->Tuning()->m_ShotgunStrength;
Strength = Tuning()->m_ShotgunStrength;
else
Strength = GameServer()->TuningList()[m_TuneZone].m_ShotgunStrength;
Strength = TuningList()[m_TuneZone].m_ShotgunStrength;
vec2 &HitPos = pHit->Core()->m_Pos;
if(!g_Config.m_SvOldLaser)
@ -158,7 +158,7 @@ void CLaser::DoBounce()
}
else if(!m_TuneZone)
{
m_Energy -= Distance + GameServer()->Tuning()->m_LaserBounceCost;
m_Energy -= Distance + Tuning()->m_LaserBounceCost;
}
else
{
@ -179,9 +179,9 @@ void CLaser::DoBounce()
m_WasTele = false;
}
int BounceNum = GameServer()->Tuning()->m_LaserBounceNum;
int BounceNum = Tuning()->m_LaserBounceNum;
if(m_TuneZone)
BounceNum = GameServer()->TuningList()[m_TuneZone].m_LaserBounceNum;
BounceNum = TuningList()[m_TuneZone].m_LaserBounceNum;
if(m_Bounces > BounceNum)
m_Energy = -1;
@ -279,9 +279,9 @@ void CLaser::Tick()
float Delay;
if(m_TuneZone)
Delay = GameServer()->TuningList()[m_TuneZone].m_LaserBounceDelay;
Delay = TuningList()[m_TuneZone].m_LaserBounceDelay;
else
Delay = GameServer()->Tuning()->m_LaserBounceDelay;
Delay = Tuning()->m_LaserBounceDelay;
if((Server()->Tick() - m_EvalTick) > (Server()->TickSpeed() * Delay / 1000.0f))
DoBounce();

View file

@ -64,13 +64,13 @@ vec2 CProjectile::GetPos(float Time)
case WEAPON_GRENADE:
if(!m_TuneZone)
{
Curvature = GameServer()->Tuning()->m_GrenadeCurvature;
Speed = GameServer()->Tuning()->m_GrenadeSpeed;
Curvature = Tuning()->m_GrenadeCurvature;
Speed = Tuning()->m_GrenadeSpeed;
}
else
{
Curvature = GameServer()->TuningList()[m_TuneZone].m_GrenadeCurvature;
Speed = GameServer()->TuningList()[m_TuneZone].m_GrenadeSpeed;
Curvature = TuningList()[m_TuneZone].m_GrenadeCurvature;
Speed = TuningList()[m_TuneZone].m_GrenadeSpeed;
}
break;
@ -78,13 +78,13 @@ vec2 CProjectile::GetPos(float Time)
case WEAPON_SHOTGUN:
if(!m_TuneZone)
{
Curvature = GameServer()->Tuning()->m_ShotgunCurvature;
Speed = GameServer()->Tuning()->m_ShotgunSpeed;
Curvature = Tuning()->m_ShotgunCurvature;
Speed = Tuning()->m_ShotgunSpeed;
}
else
{
Curvature = GameServer()->TuningList()[m_TuneZone].m_ShotgunCurvature;
Speed = GameServer()->TuningList()[m_TuneZone].m_ShotgunSpeed;
Curvature = TuningList()[m_TuneZone].m_ShotgunCurvature;
Speed = TuningList()[m_TuneZone].m_ShotgunSpeed;
}
break;
@ -92,13 +92,13 @@ vec2 CProjectile::GetPos(float Time)
case WEAPON_GUN:
if(!m_TuneZone)
{
Curvature = GameServer()->Tuning()->m_GunCurvature;
Speed = GameServer()->Tuning()->m_GunSpeed;
Curvature = Tuning()->m_GunCurvature;
Speed = Tuning()->m_GunSpeed;
}
else
{
Curvature = GameServer()->TuningList()[m_TuneZone].m_GunCurvature;
Speed = GameServer()->TuningList()[m_TuneZone].m_GunSpeed;
Curvature = TuningList()[m_TuneZone].m_GunCurvature;
Speed = TuningList()[m_TuneZone].m_GunSpeed;
}
break;
}

View file

@ -61,6 +61,9 @@ public: // TODO: Maybe make protected
/* Objects */
std::vector<SSwitchers> &Switchers() { return m_pGameWorld->m_Core.m_vSwitchers; }
CGameWorld *GameWorld() { return m_pGameWorld; }
CTuningParams *Tuning() { return GameWorld()->Tuning(); }
CTuningParams *TuningList() { return GameWorld()->TuningList(); }
CTuningParams *GetTuning(int i) { return GameWorld()->GetTuning(i); }
class CConfig *Config() { return m_pGameWorld->Config(); }
class CGameContext *GameServer() { return m_pGameWorld->GameServer(); }
class IServer *Server() { return m_pGameWorld->Server(); }

View file

@ -3480,6 +3480,7 @@ void CGameContext::OnInit(const void *pPersistentData)
m_Layers.Init(Kernel());
m_Collision.Init(&m_Layers);
m_World.m_pTuningList = m_aTuningList;
m_World.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber);
char aMapName[IO_MAX_PATH_LENGTH];

View file

@ -371,3 +371,8 @@ void CGameWorld::ReleaseHooked(int ClientID)
}
}
}
CTuningParams *CGameWorld::Tuning()
{
return &m_Core.m_aTuning[0];
}

View file

@ -164,6 +164,12 @@ public:
Returns list with all Characters on line.
*/
std::vector<CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis = nullptr);
CTuningParams *Tuning();
CTuningParams *m_pTuningList;
CTuningParams *TuningList() { return m_pTuningList; }
CTuningParams *GetTuning(int i) { return &TuningList()[i]; }
};
#endif