/* $Id: weaponhookcut.cpp,v 1.7 2005/10/17 15:13:39 pohlt Exp $ */ #include "weaponhookcut.hpp" #include "world.hpp" #include "avatar.hpp" #include "rope.hpp" #include "hook.hpp" bool WeaponHookCut::reallyShoot( World* world, Avatar* avatar, const StationaryGun* gun ) const { Rope* rope = selectRopeForAction( avatar ); if( rope ) { rope->setRemoveMeAfterUpdate( true ); return true; } return false; } /*############################################################################*/ Rope* WeaponHookCut::selectRopeForAction( const Avatar* avatar ) const { const int nAttachedObjects = avatar->getNAttachedObjects(); // prepare different rope classes const int N_ROPE_CLASSES = 4; Rope* ropeClass[N_ROPE_CLASSES]; for( int a = 0; a < N_ROPE_CLASSES; a++ ) ropeClass[a] = NULL; // go through list of attached objects for( int a = 0; a < nAttachedObjects; a++ ) { // find a rope which avatar owns if( avatar->getAttachedObject( a )->getID() != ROPE || (dynamic_cast(avatar->getAttachedObject( a )))->getOwner() != avatar->getPlayer()->getPlayerOrTeamID() ) continue; // what's at the other end of the rope? const Object* otherAttachedObject = (dynamic_cast(avatar->getAttachedObject( a )))->getOtherAttachedObject( avatar ); // nothing? strange, but don't touch if( ! otherAttachedObject ) continue; // rope will be deleted soon // set currentClass according to rope state int currentClass; if( otherAttachedObject->getID() == HOOK ) if( ((Hook*)otherAttachedObject)->isGrounded() ) currentClass = 1; else currentClass = 0; else if( otherAttachedObject->getID() == BALL ) currentClass = 3; else currentClass = 2; if( ! ropeClass[currentClass] ) ropeClass[currentClass] = dynamic_cast(avatar->getAttachedObject( a )); } // cut the rope with the lowest class and stop for( int a = 0; a < N_ROPE_CLASSES; a++ ) { if( ropeClass[a] ) return ropeClass[a]; } return NULL; }