/* $Id: weaponhookrel.cpp,v 1.11.4.1 2006/03/14 14:45:52 chfreund Exp $ */ #include "weaponhookrel.hpp" #include "world.hpp" #include "avatar.hpp" #include "rope.hpp" #include "hook.hpp" bool WeaponHookRel::reallyShoot( World* world, Avatar* avatar, const StationaryGun* gun ) const { Rope* rope = selectRopeForAction( avatar ); if( ! rope ) { return false; } // place hook Hook* const hook = dynamic_cast( world->newObject( HOOK )); CollidableObject* hitObject; Vector vel = avatar->getRandomizedAimingVector( 5 ); real velFactor = -world->getRandom().getNormedReal(); velFactor *= 5.0; velFactor += 28.0; vel *= velFactor; vel += avatar->getVel(); if( hook->initialize( avatar->placeBesideCollRect( hook->getCollRectX() + hook->getCollRectWidth() - 1, -hook->getCollRectX(), hook->getCollRectY() + hook->getCollRectHeight() - 1, -hook->getCollRectY() ), vel, hitObject ) == false ) { if( hitObject == NULL ) return false; // else hook could not be placed but an object was hit directly, so continue } else { // hook could be placed, so set hitObject to hook hitObject = hook; } // deattach rope from shooting avatar rope->detachFrom( avatar ); // attach to new hook rope->attachTo( hitObject ); return true; }