Skip to content

Commit

Permalink
Punish use of anchor (anvil) against teammates in Team GP (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
heuchi committed Mar 5, 2022
1 parent 6409e31 commit 55b67e4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/items/powerup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#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 @@ -400,6 +402,11 @@ void Powerup::use()
if(kart == m_kart) continue;
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->handleAnvilHit(m_kart->getWorldKartId(), kart->getWorldKartId());

kart->getAttachment()->set(Attachment::ATTACH_ANVIL,
stk_config->
time2Ticks(kp->getAnvilDuration()) );
Expand Down
58 changes: 58 additions & 0 deletions src/network/protocols/server_lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9393,3 +9393,61 @@ void ServerLobby::handleSwatterHit(unsigned int ownerID, unsigned int victimID,
m_teammate_swatter_punish.push_back(owner);
}
}

void ServerLobby::handleAnvilHit(unsigned int ownerID, unsigned int victimID)
{
const std::string ownername = StringUtils::wideToUtf8(
RaceManager::get()->getKartInfo(ownerID).getPlayerName());
const int ownerTeam = m_team_for_player[ownername];
if (ownerTeam == 0)
return;

const std::string victimname = StringUtils::wideToUtf8(
RaceManager::get()->getKartInfo(victimID).getPlayerName());
const int victimTeam = m_team_for_player[victimname];
if (victimTeam != ownerTeam)
return;

AbstractKart *owner = World::getWorld()->getKart(ownerID);

// should we tell the world?
if (showTeamMateHits())
{
std::string msg = ServerConfig::m_teammate_hit_msg_prefix;
msg += ownername;
msg += " just gave an anchor to teammate ";
msg += victimname;
sendTeamMateHitMsg(msg);
}
if (useTeamMateHitMode())
{
if (owner->getAttachment()->getType() == Attachment::ATTACH_BOMB)
{
// make bomb explode
owner->getAttachment()->update(10000);
}
else
{
if (owner->isShielded())
{
// if owner is shielded, take away shield
// since the anvil will also destroy the shield of the victim
// we also punish this severely
owner->decreaseShieldTime();
}

// now give anvil to owner
int left_over_ticks = 0;
// if owner already has an anvil or a parachute, make new anvil last longer
if (owner->getAttachment()->getType() == Attachment::ATTACH_ANVIL
|| owner->getAttachment()->getType() == Attachment::ATTACH_PARACHUTE)
{
left_over_ticks = owner->getAttachment()->getTicksLeft();
}
owner->getAttachment()->set(Attachment::ATTACH_ANVIL,
stk_config->time2Ticks(owner->getKartProperties()->getAnvilDuration()) + left_over_ticks);
// the powerup anvil is very strong, copy these values (from powerup.cpp)
owner->adjustSpeed(owner->getKartProperties()->getAnvilSpeedFactor() * 0.5f);
}
}
}
2 changes: 2 additions & 0 deletions src/network/protocols/server_lobby.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ class ServerLobby : public LobbyProtocol

// handle swatters
void handleSwatterHit(unsigned int ownerID, unsigned int victimID, bool success, bool has_hit_kart, uint16_t ticks_active);
// handle anvil
void handleAnvilHit(unsigned int ownerID, unsigned int victimID);

void sendTeamMateHitMsg(std::string& s);
bool showTeamMateHits() const { return m_show_teammate_hits; }
Expand Down

0 comments on commit 55b67e4

Please sign in to comment.