Exemple #1
0
void CHLDMBot :: handleWeapons ()
{
	//
	// Handle attacking at this point
	//
	if ( m_pEnemy && !hasSomeConditions(CONDITION_ENEMY_DEAD) && 
		hasSomeConditions(CONDITION_SEE_CUR_ENEMY) && wantToShoot() && 
		isVisible(m_pEnemy) && isEnemy(m_pEnemy) )
	{
		CBotWeapon *pWeapon;

		pWeapon = getBestWeapon(m_pEnemy,true,true,(m_pEnemy==m_NearestBreakable)&&!rcbot_melee_only.GetBool());

		if ( m_bWantToChangeWeapon && (pWeapon != NULL) && (pWeapon != getCurrentWeapon()) && pWeapon->getWeaponIndex() )
		{
			//selectWeaponSlot(pWeapon->getWeaponInfo()->getSlot());
			selectWeapon(pWeapon->getWeaponIndex());
		}

		setLookAtTask((LOOK_ENEMY));

		///battack = true;

		if ( !handleAttack ( pWeapon, m_pEnemy ) )
		{
			m_pEnemy = NULL;
			m_pOldEnemy = NULL;
			wantToShoot(false);
		}
	}
}
Exemple #2
0
bool CHLDMBot::checkStuck()
{
	static bool bStuck;

	if ( (bStuck = CBot::checkStuck()) == true )
	{
		if ( m_pWeapons->hasWeapon(HL2DM_WEAPON_PHYSCANNON) )
		{// check stuck on object

			CBotWeapon *currentWeapon = getCurrentWeapon();

			if ( ( currentWeapon->getID() == HL2DM_WEAPON_PHYSCANNON ) && ( m_pCarryingObject ) )
			{
				primaryAttack();
			}
			else if ( m_NearestPhysObj && (distanceFrom(m_NearestPhysObj)<100) )
			{
				if ( !m_pSchedules->hasSchedule(SCHED_GRAVGUN_PICKUP) )
				{
					m_pSchedules->freeMemory();
					CBotSchedule *pSched = new CBotSchedule(new CBotGravGunPickup(m_pCurrentWeapon,m_NearestPhysObj));
					pSched->setID(SCHED_GRAVGUN_PICKUP);
					m_pSchedules->add(pSched);
				}
			}
		}
	}

	return bStuck;
}
Exemple #3
0
    void GameProgress::setCurrentWeapon(unsigned char weapon) {
        if(getCurrentWeapon() != weapon) {
            currentWeapon = weapon;

            if(auto events = eventBus.lock()) {
                // events->triggerEvent(
                //     std::make_shared<PropertyChangedEventData>(
                //         "currentWeapon"
                //     )
                // );
            }
        }

    }
//------------------------------------------------------------------------------
// updateData() -- update non-time critical stuff here
//------------------------------------------------------------------------------
void SimpleStoresMgr::updateData(const double dt)
{
   BaseClass::updateData(dt);

   // ---
   // Get the current weapon data
   // ---
   {
      Weapon* wpn = static_cast<Weapon*>(getCurrentWeapon());
      if (wpn != nullptr) {
         // Weapon ID
         curWpnID = wpn->getWeaponID();

         // Number of this type weapon
         int count = 0;
         base::PairStream* list = getStores();
         if (list != nullptr) {
            const base::List::Item* item = list->getFirstItem();
            while (item != nullptr) {
               const base::Pair* pair = static_cast<const base::Pair*>(item->getValue());
               if (pair != nullptr) {
                  const Weapon* s = dynamic_cast<const Weapon*>( pair->object() );
                  if ( s != nullptr && s->isMode(Player::INACTIVE) && std::strcmp(s->getFactoryName(), wpn->getFactoryName()) == 0 ) {
                     count++;
                  }
               }
               item = item->getNext();
            }
            list->unref();
            list = nullptr;
         }
         nCurWpn = count;

         wpn->unref();
         wpn = nullptr;
      }
      else {
         curWpnID = 0;
         nCurWpn = 0;
      }
   }

}
void Player::update()
{
	int dt = GameManager::getInstance()->getDeltaTime();

	Shooter::update();

	updateInvincibility(dt);

	if (_controller)
	{
		if (_controller->isControllerLeft())
		{
			setPositionX( getPosition().x - getSpeed().x * dt * 0.001f );
		}

		if (_controller->isControllerRight())
		{
			setPositionX( getPosition().x + getSpeed().x * dt * 0.001f );
		}

		if (_controller->isControllerUp())
		{
			setPositionY( getPosition().y - getSpeed().y * dt * 0.001f );
		}

		if (_controller->isControllerDown())
		{
			setPositionY( getPosition().y + getSpeed().y * dt * 0.001f );
		}

		if (_controller->isControllerFire())
		{
			addShots( getCurrentWeapon()->shoot( this ) );
		}
	}

	_currentSprite.update( dt );

	boundToScreen();
}
//------------------------------------------------------------------------------
// Manage the weapon release event
//------------------------------------------------------------------------------
bool SimpleStoresMgr::onWpnRelEvent(const base::Boolean* const sw)
{
   // Weapon release follows the switch or by default is true
   bool wpnRel = true;
   if (sw != nullptr) wpnRel = sw->getBoolean();

   if ( wpnRel && (isWeaponDeliveryMode(A2A) || isWeaponDeliveryMode(A2G)) ) {

      // A/A missiles and A/G bombs only ...

      Weapon* wpn = getCurrentWeapon();
      if (wpn != nullptr) {

         // release the weapon ---
         //  if successful, returns a pre-ref()'d pointer to the flyout weapon.
         Weapon* flyout = releaseWeapon(wpn);
         if (flyout != nullptr) {

            if (isWeaponDeliveryMode(A2A)) {

               // ---
               // Setup the guidance ...
               // ---
               Track* trk = getNextTarget();
               if (trk != nullptr) {
                  Player* tgt = trk->getTarget();

                  TrackManager* tm = nullptr;
                  RfSensor* sm = flyout->getSensor();
                  if (sm != nullptr) tm = sm->getTrackManager();

                  if (tm != nullptr) {
                     // Give a copy of the track to the weapon's track manager
                     Track* newTrk = trk->clone();
                     tm->clearTracksAndQueues();
                     tm->addTrack(newTrk);
                     flyout->setTargetTrack(newTrk,true);
                  }
                  else if (tgt != nullptr) {
                     // No sensor -- fake it and just track the target
                     flyout->setTargetPlayer(tgt,true);
                  }
                  else {
                     // no target track
                  }

                  trk->setWeaponReleased(true);
               }

            }


            // Set the weapon release timer
            setWeaponReleaseTimer(1.0);
         }

         if (flyout != nullptr) flyout->unref(); // unref() the flyout

         wpn->unref();
         wpn = nullptr;
      }

   }
   else {
      setWeaponReleaseTimer(0);
   }

   return true;
}
void inputHandler() {
    while (isRunning()) {
        try {
            if(SDL_PollEvent(&event)) {
                switch (event.type) {
                case SDL_QUIT:
                    setRunning(false);
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    println("Mouse button pressed");
                    switch (event.button.button) {
                        case SDL_BUTTON_WHEELDOWN:
                            setCurrentWeapon(((((getCurrentWeapon() - 1) > 9001) && ((getCurrentWeapon() - 1) < 9007)) ? (getCurrentWeapon() - 1) :
                                #if mouseWheelWeaponChangeScrollLoop
                                    9006
                                #else
                                    getCurrentWeapon()
                                #endif
                            ));
                            break;
                        case SDL_BUTTON_WHEELUP:
                            setCurrentWeapon(((((getCurrentWeapon() + 1) > 9001) && ((getCurrentWeapon() + 1) < 9007)) ? (getCurrentWeapon() + 1) :
                                #if mouseWheelWeaponChangeScrollLoop
                                    9006
                                #else
                                    getCurrentWeapon()
                                #endif
                            ));
                            break;
                        case SDL_BUTTON_LEFT:
                        case SDL_BUTTON_RIGHT:
                            fireWeapon();
                    }
                    break;
                case SDL_MOUSEBUTTONUP:
                    println("Mouse button released");
                    setFiring(false);
                    break;
                case SDL_MOUSEMOTION:
                    SDL_GetMouseState(&mouse_x,&mouse_y);
                    #if debugMouseMovement
                        printf("Mouse movement detected. X: %d Y: %d\n",mouse_x,mouse_y);
                    #endif
                    break;
                case SDL_KEYDOWN:
                    SDLKey keyPressed = event.key.keysym.sym;
                    switch (keyPressed) {
                        case SDLK_ESCAPE:
                            println("Escape key pressed.");
                        case SDLK_F12: //in case escape doesn't get detected, we can also use F12.
                            setRunning(false);
                            break;
                        case SDLK_F1:
                            setCurrentWeapon(RIFLE);
                            break;
                        case SDLK_F2:
                            setCurrentWeapon(MACHINE_GUN);
                            break;
                        case SDLK_F3:
                            setCurrentWeapon(SHOTGUN);
                            break;
                        case SDLK_F4:
                            setCurrentWeapon(MACHINE_SHOTGUN);
                            break;
                        case SDLK_F5:
                            setCurrentWeapon(FLAMETHROWER);
                            break;
                        case SDLK_HOME:
                            toggleAlphaVisible();
                            println("Home key pressed. Toggling alpha test visibility.");
                            break;
                        case SDLK_DELETE:
                            println("Delete key pressed. Removing all damage, and resetting the game");
                            resetGame();
                            break;
                        case SDLK_F11:
                            println("F11 pressed. Toggling fullscreen...");
                            toggleFullscreen();
                            break;
                        default:
                            printf("An unhandled key was pressed: ");
                            displayKey(&event.key);
                        }
                    break;
                }
            }
        } catch(...) {
            println("Exception occurred handling input...");
        }
    }
}
Exemple #8
0
void CHLDMBot :: modThink ()
{
	m_fIdealMoveSpeed = CClassInterface::getMaxSpeed(m_pEdict);

	// update hitbox hull
	//m_pEdict->GetCollideable()->GetCollisionOrigin();

	if ( !CBotGlobals::entityIsValid(m_NearestPhysObj) )
		m_NearestPhysObj = NULL;

	if ( !CBotGlobals::entityIsValid(m_FailedPhysObj) )
		m_FailedPhysObj = NULL;

	//if ( m_pWeapons )
	//	m_pWeapons->update();

	//if ( m_fFixWeaponTime < engine->Time() )
	//{

	m_pCurrentWeapon = CClassInterface::getCurrentWeapon(m_pEdict);
	//	m_fFixWeaponTime = engine->Time() + 1.0f;
	//}

	if ( m_pCurrentWeapon )
		CClassInterface::getWeaponClip(m_pCurrentWeapon,&m_iClip1,&m_iClip2);

	if ( CClassInterface::onLadder(m_pEdict) != NULL )
	{
		setMoveLookPriority(MOVELOOK_OVERRIDE);
		setLookAtTask(LOOK_WAYPOINT);
		m_pButtons->holdButton(IN_FORWARD,0,1,0);
		setMoveLookPriority(MOVELOOK_MODTHINK);
	}

	if ( (m_fCurrentDanger >= 20.0f) && (CClassInterface::auxPower(m_pEdict) > 90.f ) && (m_flSprintTime < engine->Time()))
	{
		m_pButtons->holdButton(IN_SPEED,0,1,0);
	}
	else if (( m_fCurrentDanger < 1 ) || (CClassInterface::auxPower(m_pEdict) < 5.0f ))
	{
		m_flSprintTime = engine->Time() + randomFloat(5.0f,20.0f);
	}

	if ( m_fLastSeeEnemy && ((m_fLastSeeEnemy + 5.0)<engine->Time()) )
	{
		CBotWeapon *pWeapon = getCurrentWeapon();

		if ( pWeapon && (pWeapon->getClip1(this)==0) && (pWeapon->getAmmo(this) > 0 ) )
		{
			m_fLastSeeEnemy = 0;
			m_pButtons->tap(IN_RELOAD);
		}
	}

	if ( m_NearestPhysObj.get() )
	{
		bool bCarry = false;
		edict_t *pEntity = m_NearestPhysObj.get();

		if ( m_pCurrentWeapon && !strcmp("weapon_physcannon",m_pCurrentWeapon->GetClassName()) )
		{
			m_pCarryingObject = CClassInterface::gravityGunObject(m_pCurrentWeapon);
			bCarry = (CClassInterface::gravityGunObject(m_pCurrentWeapon) == m_NearestPhysObj.get());
		}

		if ( !bCarry && (distanceFrom(pEntity) < rcbot_jump_obst_dist.GetFloat()) )
		{
			bool bCanJump = false;
			float fTime = 0;

			if ( willCollide(pEntity,&bCanJump,&fTime) )
			{
				if ( bCanJump && (fTime < 1.5f) ) // one second to jump
				{
					if ( randomInt(0,1) )
						jump();
				}
			}
		}
	}
}