Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General cleanup part 2, and GP related updates #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/items/bowling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#include "graphics/material.hpp"
#include "io/xml_node.hpp"
#include "karts/abstract_kart.hpp"
#include "guiengine/engine.hpp"
#include "config/stk_config.hpp"
// #include "modes/linear_world.hpp"

#include "network/protocols/server_lobby.hpp"

#include "utils/hit_processor.hpp"
#include "utils/log.hpp" //TODO: remove after debugging is done

Expand Down Expand Up @@ -157,20 +157,20 @@ bool Bowling::updateAndDelete(int ticks)
*/
bool Bowling::hit(AbstractKart* kart, PhysicalObject* obj)
{
auto sl = LobbyProtocol::get<ServerLobby>();
if (sl)
sl->getHitProcessor()->setTeammateHitOwner(getOwnerId(),m_ticks_since_thrown);
auto hp = kart->getHitProcessor();
if (hp)
hp->setTeammateHitOwner(getOwnerId(),m_ticks_since_thrown);

bool was_real_hit = Flyable::hit(kart, obj);
if (was_real_hit)
{
if (kart && kart->isShielded())
{
kart->decreaseShieldTime();
if (sl)
if (hp)
{
sl->getHitProcessor()->registerTeammateHit(kart->getWorldKartId());
sl->getHitProcessor()->handleTeammateHits();
hp->registerTeammateHit(kart->getWorldKartId());
hp->handleTeammateHits();
}
return true;
}
Expand All @@ -180,8 +180,8 @@ bool Bowling::hit(AbstractKart* kart, PhysicalObject* obj)
explode(kart, obj, /*hit_secondary*/false);
}
}
if (sl)
sl->getHitProcessor()->handleTeammateHits();
if (hp)
hp->handleTeammateHits();
return was_real_hit;
} // hit

Expand Down
18 changes: 8 additions & 10 deletions src/items/cake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include "utils/hit_processor.hpp"
#include "utils/random_generator.hpp"

#include "network/protocols/server_lobby.hpp"

#include "utils/log.hpp" //TODO: remove after debugging is done

float Cake::m_st_max_distance_squared;
Expand Down Expand Up @@ -64,28 +62,28 @@ void Cake::init(const XMLNode &node, scene::IMesh *cake_model)
*/
bool Cake::hit(AbstractKart* kart, PhysicalObject* obj)
{
auto sl = LobbyProtocol::get<ServerLobby>();
if (sl)
sl->getHitProcessor()->setTeammateHitOwner(getOwnerId());
auto hp = kart->getHitProcessor();
if (hp)
hp->setTeammateHitOwner(getOwnerId());

bool was_real_hit = Flyable::hit(kart, obj);
if (was_real_hit)
{
if (kart && kart->isShielded())
{
kart->decreaseShieldTime();
if (sl)
if (hp)
{
sl->getHitProcessor()->registerTeammateHit(kart->getWorldKartId());
sl->getHitProcessor()->handleTeammateHits();
hp->registerTeammateHit(kart->getWorldKartId());
hp->handleTeammateHits();
}
return false; //Not sure if a shield hit is a real hit.
}
explode(kart, obj);
}

if (sl)
sl->getHitProcessor()->handleTeammateHits();
if (hp)
hp->handleTeammateHits();
return was_real_hit;
} // hit

Expand Down
8 changes: 3 additions & 5 deletions src/items/powerup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
#include "utils/string_utils.hpp"
#include "utils/log.hpp" //TODO: remove after debugging is done

#include "network/protocols/server_lobby.hpp"

//-----------------------------------------------------------------------------
/** Constructor, stores the kart to which this powerup belongs.
* \param kart The kart to which this powerup belongs.
Expand Down Expand Up @@ -404,9 +402,9 @@ void Powerup::use()
if(kart->getPosition() == 1)
{
// check if we are in team gp and hit a teammate and should punish the attacker
auto sl = LobbyProtocol::get<ServerLobby>();
if(sl && !kart->hasFinishedRace())
sl->getHitProcessor()->handleAnvilHit(m_kart->getWorldKartId(), kart->getWorldKartId());
auto hp = kart->getHitProcessor();
if(hp && !kart->hasFinishedRace())
hp->handleAnvilHit(m_kart->getWorldKartId(), kart->getWorldKartId());

kart->getAttachment()->set(Attachment::ATTACH_ANVIL,
stk_config->
Expand Down
9 changes: 4 additions & 5 deletions src/items/swatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "modes/capture_the_flag.hpp"
#include "network/network_string.hpp"
#include "network/rewind_manager.hpp"
#include "network/protocols/server_lobby.hpp"
#include "utils/hit_processor.hpp"
#include <IAnimatedMeshSceneNode.h>

Expand Down Expand Up @@ -398,7 +397,7 @@ void Swatter::squashThingsAround()
const KartProperties *kp = m_kart->getKartProperties();

float duration = kp->getSwatterSquashDuration();
float slowdown = kp->getSwatterSquashSlowdown();
float slowdown = kp->getSwatterSquashSlowdown();
// The squash attempt may fail because of invulnerability, shield, etc.
// Making a bomb explode counts as a success
bool wasHit = !m_closest_kart->isInvulnerable() && !m_closest_kart->getKartAnimation();
Expand All @@ -411,9 +410,9 @@ void Swatter::squashThingsAround()
if (wasHit)
{
// check if we are in team gp and hit a teammate and should punish attacker
auto sl = LobbyProtocol::get<ServerLobby>();
if (sl && !m_closest_kart->hasFinishedRace())
sl->getHitProcessor()->handleSwatterHit(m_kart->getWorldKartId(),
auto hp = m_kart->getHitProcessor();
if (hp && !m_closest_kart->hasFinishedRace())
hp->handleSwatterHit(m_kart->getWorldKartId(),
m_closest_kart->getWorldKartId(), success, m_has_hit_kart,
World::getWorld()->getTicksSinceStart() - m_created_ticks);
}
Expand Down
7 changes: 7 additions & 0 deletions src/karts/abstract_kart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "karts/kart_properties_manager.hpp"
#include "karts/official_karts.hpp"
#include "network/network_config.hpp"
#include "utils/hit_processor.hpp"
#include "physics/physics.hpp"
#include "utils/log.hpp"
#include "utils/string_utils.hpp"
Expand Down Expand Up @@ -276,3 +277,9 @@ void AbstractKart::makeKartRest()
body->proceedToTransform(t);
setTrans(t);
} // makeKartRest

// ----------------------------------------------------------------------------
std::shared_ptr<HitProcessor> AbstractKart::getHitProcessor() const
{
return RaceManager::get()->getHitProcessor();
} // getHitProcessor
3 changes: 3 additions & 0 deletions src/karts/abstract_kart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "karts/moveable.hpp"
#include "karts/controller/kart_control.hpp"
#include "race/race_manager.hpp"
class HitProcessor;

namespace irr
{
Expand Down Expand Up @@ -550,6 +551,8 @@ class AbstractKart : public Moveable
/** Return the confirmed finish ticks (sent by the server)
* indicating that this kart has really finished the race. */
virtual int getNetworkConfirmedFinishTicks() const = 0;
// ------------------------------------------------------------------------
std::shared_ptr<HitProcessor> getHitProcessor() const;
}; // AbstractKart


Expand Down
11 changes: 5 additions & 6 deletions src/karts/explosion_animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "modes/follow_the_leader.hpp"
#include "network/network_string.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/protocols/server_lobby.hpp"
#include "race/race_manager.hpp"
#include "tracks/track.hpp"
#include "utils/hit_processor.hpp"
Expand Down Expand Up @@ -57,13 +56,13 @@ ExplosionAnimation *ExplosionAnimation::create(AbstractKart *kart,
// Ignore explosion that are too far away.
if(!direct_hit && pos.distance2(kart->getXYZ())>r*r) return NULL;

auto sl = LobbyProtocol::get<ServerLobby>();
auto hp = kart->getHitProcessor();

if(kart->isShielded())
{
kart->decreaseShieldTime();
if (sl)
sl->getHitProcessor()->registerTeammateHit(kart->getWorldKartId());
if (hp)
hp->registerTeammateHit(kart->getWorldKartId());
return NULL;
}

Expand All @@ -75,8 +74,8 @@ ExplosionAnimation *ExplosionAnimation::create(AbstractKart *kart,
ftl_world->leaderHit();
}

if (sl)
sl->getHitProcessor()->registerTeammateExplode(kart->getWorldKartId());
if (hp)
hp->registerTeammateExplode(kart->getWorldKartId());
return new ExplosionAnimation(kart, direct_hit);
} // create

Expand Down
4 changes: 2 additions & 2 deletions src/network/database_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ void DatabaseConnector::onPlayerJoinQueries(std::shared_ptr<STKPeer> peer,
peer->getAddress().toString(false),
peer->getAddress().getPort(),
online_id,
Binder(coll, StringUtils::wideToUtf8(peer->getPlayerProfiles()[0]->getName()), "player_name"),
Binder(coll, peer->getMainName(), "player_name"),
player_count,
Binder(coll, country_code, "country_code", true),
Binder(coll, version_os.first, "version"),
Expand All @@ -1043,7 +1043,7 @@ void DatabaseConnector::onPlayerJoinQueries(std::shared_ptr<STKPeer> peer,
peer->getAddress().getIP(),
peer->getAddress().getPort(),
online_id,
Binder(coll, StringUtils::wideToUtf8(peer->getPlayerProfiles()[0]->getName()), "player_name"),
Binder(coll, peer->getMainName(), "player_name"),
player_count,
Binder(coll, country_code, "country_code", true),
Binder(coll, version_os.first, "version"),
Expand Down
7 changes: 4 additions & 3 deletions src/network/game_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "network/stk_host.hpp"
#include "race/race_manager.hpp"
#include "utils/file_utils.hpp"
#include "utils/lobby_settings.hpp"
#include "utils/log.hpp"
#include "utils/stk_process.hpp"
#include "utils/string_utils.hpp"
Expand Down Expand Up @@ -138,14 +139,14 @@ void GameSetup::addServerInfo(NetworkString* ns)
if (ServerConfig::m_owner_less)
{
ns->addUInt8(ServerConfig::m_min_start_game_players)
.addFloat(std::max<float>(0.0f, ServerConfig::m_start_game_counter));
.addFloat(std::max<float>(0.0f, getSettings()->getStartGameCounter()));
}
else
ns->addUInt8(0).addFloat(0.0f);

ns->encodeString16(m_message_of_today);
ns->addUInt8((uint8_t)ServerConfig::m_server_configurable);
ns->addUInt8(ServerConfig::m_live_players? 1 : 0);
ns->addUInt8((uint8_t)getSettings()->getServerConfigurable());
ns->addUInt8(getSettings()->isLivePlayers() ? 1 : 0);
} // addServerInfo

//-----------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/network/game_setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define GAME_SETUP_HPP

#include <irrString.h>
#include "utils/lobby_context.hpp"

#include <atomic>
#include <cassert>
Expand All @@ -39,7 +40,7 @@ class PeerVote;
* \brief Used to store the needed data about the players that join a game.
* This class stores all the possible information about players in a lobby.
*/
class GameSetup
class GameSetup: public LobbyContextUser
{
private:
std::vector<std::string> m_tracks;
Expand Down
Loading
Loading