From: <Jef...@us...> - 2008-04-23 04:42:35
|
Revision: 17069 http://bzflag.svn.sourceforge.net/bzflag/?rev=17069&view=rev Author: JeffM2501 Date: 2008-04-22 21:42:42 -0700 (Tue, 22 Apr 2008) Log Message: ----------- move more of the death stuff to the player objects. Modified Paths: -------------- branches/v2_99_shot_branch/src/bzflag/LocalPlayer.cxx branches/v2_99_shot_branch/src/bzflag/LocalPlayer.h branches/v2_99_shot_branch/src/bzflag/Player.cxx branches/v2_99_shot_branch/src/bzflag/Player.h branches/v2_99_shot_branch/src/bzflag/RemotePlayer.cxx branches/v2_99_shot_branch/src/bzflag/RemotePlayer.h branches/v2_99_shot_branch/src/bzflag/RobotPlayer.cxx branches/v2_99_shot_branch/src/bzflag/RobotPlayer.h branches/v2_99_shot_branch/src/bzflag/playing.cxx Modified: branches/v2_99_shot_branch/src/bzflag/LocalPlayer.cxx =================================================================== --- branches/v2_99_shot_branch/src/bzflag/LocalPlayer.cxx 2008-04-23 02:43:37 UTC (rev 17068) +++ branches/v2_99_shot_branch/src/bzflag/LocalPlayer.cxx 2008-04-23 04:42:42 UTC (rev 17069) @@ -1311,6 +1311,31 @@ } } +void LocalPlayer::killTeammate ( PlayerId player ) +{ + BaseLocalPlayer::killTeammate(); + + hud->setAlert(1, "Don't kill teammates!!!", 3.0f, true); + playLocalSound(SFX_KILL_TEAM); + + if (isAutoPilot()) + { + char meaculpa[MessageLen]; + memset(meaculpa, 0, MessageLen); + strncpy(meaculpa, "sorry, i'm just a silly machine", MessageLen); + serverLink->sendMessage(player, meaculpa); + } +} + +void LocalPlayer::killPlayer ( PlayerId player ) +{ + if (player = getId()) + return; // yeah, I'm stupid + + setNemesis(getPlayerByIndex(player)); +} + + bool LocalPlayer::fireShot() { if (! (firingStatus == Ready || firingStatus == Zoned)) Modified: branches/v2_99_shot_branch/src/bzflag/LocalPlayer.h =================================================================== --- branches/v2_99_shot_branch/src/bzflag/LocalPlayer.h 2008-04-23 02:43:37 UTC (rev 17068) +++ branches/v2_99_shot_branch/src/bzflag/LocalPlayer.h 2008-04-23 04:42:42 UTC (rev 17069) @@ -112,6 +112,8 @@ virtual void gotShot ( unsigned int shotID ); virtual void dropFlag ( void ); virtual void died ( void ); + virtual void killTeammate ( PlayerId player ); + virtual void killPlayer ( PlayerId player ); static LocalPlayer* getMyTank(); static void setMyTank(LocalPlayer*); Modified: branches/v2_99_shot_branch/src/bzflag/Player.cxx =================================================================== --- branches/v2_99_shot_branch/src/bzflag/Player.cxx 2008-04-23 02:43:37 UTC (rev 17068) +++ branches/v2_99_shot_branch/src/bzflag/Player.cxx 2008-04-23 04:42:42 UTC (rev 17069) @@ -532,9 +532,26 @@ { // can't take it with you dropFlag(); + + explodeTank(); + EFFECTS.addDeathEffect(getColor(), getPosition(), getAngle()); + + if (isViewTank()) + ForceFeedback::death(); } +void Player::killTeammate ( PlayerId player ) +{ + // jack +} + +void Player::killPlayer ( PlayerId player ) +{ + // jack +} + + void Player::setExplode(const TimeKeeper& t) { if (!isAlive()) return; Modified: branches/v2_99_shot_branch/src/bzflag/Player.h =================================================================== --- branches/v2_99_shot_branch/src/bzflag/Player.h 2008-04-23 02:43:37 UTC (rev 17068) +++ branches/v2_99_shot_branch/src/bzflag/Player.h 2008-04-23 04:42:42 UTC (rev 17069) @@ -110,6 +110,8 @@ virtual void gotShot ( unsigned int shotID ); virtual void died ( void ); virtual void dropFlag ( void ); + virtual void killTeammate ( PlayerId player ); + virtual void killPlayer ( PlayerId player ); #ifndef BUILDING_BZADMIN inline const float* getColor() const Modified: branches/v2_99_shot_branch/src/bzflag/RemotePlayer.cxx =================================================================== --- branches/v2_99_shot_branch/src/bzflag/RemotePlayer.cxx 2008-04-23 02:43:37 UTC (rev 17068) +++ branches/v2_99_shot_branch/src/bzflag/RemotePlayer.cxx 2008-04-23 04:42:42 UTC (rev 17069) @@ -40,6 +40,18 @@ Player::addShot(new RemoteShotPath(info,syncedClock.GetServerSeconds()), info); } +void RemotePlayer::died( void) +{ + Player::died(); + + const float* pos = getPosition(); + float explodePos[3]; + explodePos[0] = pos[0]; + explodePos[1] = pos[1]; + explodePos[2] = pos[2] + getMuzzleHeight(); + addTankExplosion(explodePos); +} + // Local Variables: *** // mode: C++ *** // tab-width: 8 *** Modified: branches/v2_99_shot_branch/src/bzflag/RemotePlayer.h =================================================================== --- branches/v2_99_shot_branch/src/bzflag/RemotePlayer.h 2008-04-23 02:43:37 UTC (rev 17068) +++ branches/v2_99_shot_branch/src/bzflag/RemotePlayer.h 2008-04-23 04:42:42 UTC (rev 17069) @@ -34,6 +34,7 @@ ~RemotePlayer(); void addShot(FiringInfo&); + virtual void died ( void ); private: int numShots; Modified: branches/v2_99_shot_branch/src/bzflag/RobotPlayer.cxx =================================================================== --- branches/v2_99_shot_branch/src/bzflag/RobotPlayer.cxx 2008-04-23 02:43:37 UTC (rev 17068) +++ branches/v2_99_shot_branch/src/bzflag/RobotPlayer.cxx 2008-04-23 04:42:42 UTC (rev 17069) @@ -512,7 +512,24 @@ } } +void RobotPlayer::gotShot ( unsigned int shotID ) +{ + BaseLocalPlayer::gotShot(shotID); +} +void RobotPlayer::killTeammate ( PlayerId player ) +{ + BaseLocalPlayer::killTeammate(player); + + char meaculpa[MessageLen]; + memset(meaculpa, 0, MessageLen); + strncpy(meaculpa, "sorry, i'm just a silly machine", MessageLen); + serverLink->sendMessage(player, meaculpa); + +} + + + // Local Variables: *** // mode: C++ *** // tab-width: 8 *** Modified: branches/v2_99_shot_branch/src/bzflag/RobotPlayer.h =================================================================== --- branches/v2_99_shot_branch/src/bzflag/RobotPlayer.h 2008-04-23 02:43:37 UTC (rev 17068) +++ branches/v2_99_shot_branch/src/bzflag/RobotPlayer.h 2008-04-23 04:42:42 UTC (rev 17069) @@ -44,6 +44,10 @@ void restart(const float* pos, float azimuth); void explodeTank(); + virtual void gotShot ( unsigned int shotID ); + virtual void killTeammate ( PlayerId player ); + virtual void died ( void ); + private: void doUpdate(float dt); void doUpdateMotion(float dt); @@ -59,7 +63,6 @@ void projectPosition(const Player *targ,const float t,float &x,float &y,float &z) const; void getProjectedPosition(const Player *targ, float *projpos) const; - virtual void gotShot ( unsigned int shotID ); private: const Player* target; Modified: branches/v2_99_shot_branch/src/bzflag/playing.cxx =================================================================== --- branches/v2_99_shot_branch/src/bzflag/playing.cxx 2008-04-23 02:43:37 UTC (rev 17068) +++ branches/v2_99_shot_branch/src/bzflag/playing.cxx 2008-04-23 04:42:42 UTC (rev 17069) @@ -2097,6 +2097,17 @@ controlPanel->addMessage(message); } +bool teamKill ( Player* killer, Player* victim ) +{ + if (killer == victim ) + return false; + + if (!allowTeams() || !World::getWorld()->allowTeamKills() || killer->getTeam() == RogueTeam ) + return false; + + return killer->getTeam() == victim->getTeam(); +} + static void handleDeathByShot ( int playerID, bool human, unsigned int shotID ) { Player* player = getPlayerByIndex(playerID); @@ -2105,34 +2116,173 @@ return; player->gotShot(shotID); + playSoundForPlayer(playerID,SFX_EXPLOSION); - if (player == myTank) + ShotPath *shot = ShotList::instance().getShot(shotID); + + if(player->isAutoPilot()) + teachAutoPilot(shot->getFlag(), 1); + + Player *killer = getPlayerByIndex(shot->getPlayer()); + if (!killer) + { + addMessage(player, "destroyed by a (GHOST)"); + return; + } + + killer->killPlayer(playerID); + + bool tk = teamKill(killer,player); + + if(tk) + killer->killTeammate(playerID); + + if (player == myTank && killer == myTank) printDeathMessage(std::string("Shot Myself")); else { - // get the death message + std::string playerStr; + if (tk) + playerStr += "teammate "; + + if (player == myTank) + { + if (BZDB.get("killerhighlight") == "1") + playerStr += ColorStrings[PulsatingColor]; + else if (BZDB.get("killerhighlight") == "2") + playerStr += ColorStrings[UnderlineColor]; + } + + int color = killerPlayer->getTeam(); + playerStr += ColorStrings[color]; + playerStr += killerPlayer->getCallSign(); + + if (victimPlayer == myTank) + playerStr += ColorStrings[ResetColor]; + + playerStr += ColorStrings[WhiteColor]; + + FlagType *flagType = shot->getFlag(); + + // Give more informative kill messages + if (flagType == Flags::Laser) + message += "was fried by " + playerStr + "'s laser"; + else if (flagType == Flags::GuidedMissile) + message += "was destroyed by " + playerStr + "'s guided missile"; + else if (flagType == Flags::ShockWave) + message += "felt the effects of " + playerStr + "'s shockwave"; + else if (flagType == Flags::InvisibleBullet) + message += "didn't see " + playerStr + "'s bullet"; + else if (flagType == Flags::MachineGun) + message += "was turned into swiss cheese by " + playerStr + "'s machine gun"; + else if (flagType == Flags::SuperBullet) + message += "got skewered by " + playerStr + "'s super bullet"; + else + message += "killed by " + playerStr; + + addMessage(player, message, 3, killer==myTank); } - playSoundForPlayer(playerID,SFX_EXPLOSION); } -static void handleDeathBySquish ( int playerID, bool human, int squiser ) +static void handleDeathBySquish ( int playerID, bool human, int squisher ) { + Player* player = getPlayerByIndex(playerID); + if (!player) + return; + + player->died(); + + playSoundForPlayer(playerID,SFX_RUNOVER); + + Player *killer = getPlayerByIndex(squisher); + if (!killer) + { + addMessage(player, "destroyed by a (GHOST)"); + return; + } + + killer->killPlayer(playerID); + + bool tk = teamKill(killer,player); + + if(tk) + killer->killTeammate(playerID); + + if (player == myTank && killer == myTank) + printDeathMessage(std::string("Shot Myself")); // HOW? + else + { + std::string playerStr; + if (tk) + playerStr += "teammate "; + + if (player == myTank) + { + if (BZDB.get("killerhighlight") == "1") + playerStr += ColorStrings[PulsatingColor]; + else if (BZDB.get("killerhighlight") == "2") + playerStr += ColorStrings[UnderlineColor]; + } + + int color = killerPlayer->getTeam(); + playerStr += ColorStrings[color]; + playerStr += killerPlayer->getCallSign(); + + if (victimPlayer == myTank) + playerStr += ColorStrings[ResetColor]; + + playerStr += ColorStrings[WhiteColor]; + + message += "run over by " + playerStr; + + addMessage(player, message, 3, killer==myTank); + } } static void handleDeathByDriver ( int playerID, bool human, int id ) { + Player* player = getPlayerByIndex(playerID); + if (!player) + return; + + player->died(); + + std::string message(ColorStrings[WhiteColor]); + const PhysicsDriver* driver = PHYDRVMGR.getDriver(id); + if (driver == NULL) + message += "Unknown Deadly Obstacle"; + else + message += driver->getDeathMsg(); + + addMessage(victimPlayer, message); } static void handleDeathByDrowning ( int playerID, bool human ) { + Player* player = getPlayerByIndex(playerID); + if (!player) + return; + + player->died(); + + std::string message(ColorStrings[WhiteColor]); + message += "fell in the water"; + addMessage(player, message); } static void handleDeathBySmite ( int playerID, bool human ) { + Player* player = getPlayerByIndex(playerID); + if (!player) + return; + + player->died(); + + addMessage(player, "destroyed by the server"); } static void handleKilledMessage(void *msg, bool human, bool &checkScores) @@ -2148,8 +2298,8 @@ switch ((BlowedUpReason)reason) { default: - handleDeathBySmite(victim,human); - break; + handleDeathBySmite(victim,human); + break; case GotShot: case GenocideEffect: @@ -2169,160 +2319,6 @@ break; } - if (killerLocal) - { - // local player did it - if (shotId >= 0) - killerLocal->endShot(shotId, true); // terminate the shot - - if (victimPlayer && killerLocal != victimPlayer) - { - if ((victimPlayer->getTeam() == killerLocal->getTeam()) && (killerLocal->getTeam() != RogueTeam) && !(killerPlayer == myTank && wasRabbit) && World::getWorld()->allowTeams()) - { - // teamkill - if (killerPlayer == myTank) - { - hud->setAlert(1, "Don't kill teammates!!!", 3.0f, true); - playLocalSound(SFX_KILL_TEAM); - if (myTank->isAutoPilot()) - { - char meaculpa[MessageLen]; - memset(meaculpa, 0, MessageLen); - strncpy(meaculpa, "sorry, i'm just a silly machine", MessageLen); - serverLink->sendMessage(victimPlayer->getId(), meaculpa); - } - } - } - else - { - // enemy - if (myTank->isAutoPilot()) - { - if (killerPlayer) - { - const ShotPath* shot = killerPlayer->getShot(int(shotId)); - if (shot != NULL) - teachAutoPilot(shot->getFlag(), 1); - } - } - } - } - } - - // handle my personal score against other players - if ((killerPlayer == myTank || victimPlayer == myTank) && !(killerPlayer == myTank && victimPlayer == myTank)) { - if (killerLocal == myTank) { - if (victimPlayer) - victimPlayer->changeLocalScore(1, 0, 0); - - myTank->setNemesis(victimPlayer); - } else { - if (killerPlayer) - killerPlayer->changeLocalScore(0, 1, killerPlayer->getTeam() == victimPlayer->getTeam() ? 1 : 0); - - myTank->setNemesis(killerPlayer); - } - } - - // add message - if (human && victimPlayer) { - std::string message(ColorStrings[WhiteColor]); - if (killerPlayer == victimPlayer) { - message += "blew myself up"; - addMessage(victimPlayer, message); - } else if (killer >= LastRealPlayer) { - addMessage(victimPlayer, "destroyed by the server"); - } else if (!killerPlayer) { - addMessage(victimPlayer, "destroyed by a (GHOST)"); - } else if (reason == WaterDeath) { - message += "fell in the water"; - addMessage(victimPlayer, message); - } else if (reason == PhysicsDriverDeath) { - const PhysicsDriver* driver = PHYDRVMGR.getDriver(phydrv); - if (driver == NULL) { - message += "Unknown Deadly Obstacle"; - } else { - message += driver->getDeathMsg(); - } - - addMessage(victimPlayer, message); - } else { - std::string playerStr; - if (World::getWorld()->allowTeams() && (killerPlayer->getTeam() == victimPlayer->getTeam()) && (killerPlayer->getTeam() != RogueTeam) && (killerPlayer->getTeam() != ObserverTeam)) { - playerStr += "teammate "; - } - - if (victimPlayer == myTank) { - if (BZDB.get("killerhighlight") == "1") { - playerStr += ColorStrings[PulsatingColor]; - } else if (BZDB.get("killerhighlight") == "2") { - playerStr += ColorStrings[UnderlineColor]; - } - } - - int color = killerPlayer->getTeam(); - playerStr += ColorStrings[color]; - playerStr += killerPlayer->getCallSign(); - - if (victimPlayer == myTank) - playerStr += ColorStrings[ResetColor]; - - playerStr += ColorStrings[WhiteColor]; - - // Give more informative kill messages - if (flagType == Flags::Laser) - message += "was fried by " + playerStr + "'s laser"; - else if (flagType == Flags::GuidedMissile) - message += "was destroyed by " + playerStr + "'s guided missile"; - else if (flagType == Flags::ShockWave) - message += "felt the effects of " + playerStr + "'s shockwave"; - else if (flagType == Flags::InvisibleBullet) - message += "didn't see " + playerStr + "'s bullet"; - else if (flagType == Flags::MachineGun) - message += "was turned into swiss cheese by " + playerStr + "'s machine gun"; - else if (flagType == Flags::SuperBullet) - message += "got skewered by " + playerStr + "'s super bullet"; - else - message += "killed by " + playerStr; - - addMessage(victimPlayer, message, 3, killerPlayer==myTank); - } - } - - // geno only works in team games :) - if (World::getWorld()->allowTeams()) { - // blow up if killer has genocide flag and i'm on same team as victim - // (and we're not rogues, unless in rabbit mode) - if (human && killerPlayer && victimPlayer && - victimPlayer != myTank && - (victimPlayer->getTeam() == myTank->getTeam()) && - (myTank->getTeam() != RogueTeam) && - (shotId >= 0)) { - // now see if shot was fired with a GenocideFlag - const ShotPath* shot = killerPlayer->getShot(int(shotId)); - - //but make sure that if we are not allowing teamkills, the victim was not a suicide - if (shot && shot->getFlag() == Flags::Genocide && - (killerPlayer != victimPlayer || World::getWorld()->allowTeamKills())) { - // go boom - gotBlowedUp(myTank, GenocideEffect, killerPlayer->getId()); - } - } - } - -#ifdef ROBOT - // blow up robots on victim's team if shot was genocide - if (killerPlayer && victimPlayer && shotId >= 0) { - const ShotPath* shot = killerPlayer->getShot(int(shotId)); - if (shot && shot->getFlag() == Flags::Genocide) { - for (int i = 0; i < numRobots; i++) { - if (robots[i] && victimPlayer != robots[i] && victimPlayer->getTeam() == robots[i]->getTeam() && robots[i]->getTeam() != RogueTeam) - gotBlowedUp(robots[i], GenocideEffect, killerPlayer->getId()); - } - } - } -#endif - checkScores = true; } @@ -6425,12 +6421,15 @@ if (destructCountdown > 0.0f) { const int oldDestructCountdown = (int)(destructCountdown + 0.99f); destructCountdown -= dt; - if (destructCountdown <= 0.0f) { + if (destructCountdown <= 0.0f) + { // now actually destruct gotBlowedUp( myTank, SelfDestruct, myTank->getId() ); hud->setAlert(1, NULL, 0.0f, true); - } else if ((int)(destructCountdown + 0.99f) != oldDestructCountdown) { + } + else if ((int)(destructCountdown + 0.99f) != oldDestructCountdown) + { // update countdown alert char msgBuf[40]; sprintf(msgBuf, "Self Destructing in %d", (int)(destructCountdown + 0.99f)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |