1 /* $Id: weapongrenade.cpp,v 1.22.2.1 2006/03/14 14:45:52 chfreund Exp $ */
2 
3 #include "weapongrenade.hpp"
4 #include "world.hpp"
5 #include "avatar.hpp"
6 #include "stationarygun.hpp"
7 
reallyShoot(World * world,Avatar * avatar,const StationaryGun * gun) const8 bool WeaponGrenade::reallyShoot( World* world, Avatar* avatar,
9                                  const StationaryGun* gun ) const {
10 	// initialize grenade
11 	real power = world->getRandom().getNormedReal();
12 	power *= 2;
13 	power += 7;
14 	Uint32 type = m_type;
15 
16 	// dud? remove any triggering
17 	if( world->getRandom().getUint32Between( 0, 10 ) == 0) {
18 		type &= ~(Grenade::TIME_TRIGGERED | Grenade::CONTACT_TRIGGERED);
19 	}
20 
21 	const Uint32 ttl = world->getRandom().getUint32Between( 60, 75 );
22 	Grenade* const grenade = dynamic_cast<Grenade*>( world->newObject( GRENADE ));
23 
24 	if( gun ) {
25 		Vector vel = gun->getRandomizedAimingVector( 2 );
26 		vel *= power;
27 		vel *= 2.0;
28 		return grenade->initialize(
29 		       gun->getShootingPoint(), vel,
30 		       avatar->getPlayer()->getPlayerID(), type, ROUND( 0.25*ttl ), 250, 18 );
31 	}
32 	else {
33 		Vector vel = avatar->getRandomizedAimingVector( 2 );
34 		vel *= power;
35 		vel += avatar->getVel();
36 		return grenade->initialize(
37 		       avatar->placeBesideCollRect( grenade->getCollRectX() + grenade->getCollRectWidth() - 1,
38 		                                    -grenade->getCollRectX(),
39 		                                    grenade->getCollRectY() + grenade->getCollRectHeight() - 1,
40 		                                    -grenade->getCollRectY() ),
41 		       vel,
42 		       avatar->getPlayer()->getPlayerID(), type, ttl, 250, 18 );
43 	}
44 }
45