Exemplo n.º 1
0
void CSpammer::Update(float frameTime, uint32 frameId)
{
	BaseFiremode::Update(frameTime, frameId);

	UpdatePotentialTargets();

	switch (m_state)
	{
		case EState_None:
			m_nextFireTimer -= frameTime;
			if (m_nextFireTimer < 0.0f)
			{
				if (m_firingPending)
					StartFire();
				m_nextFireTimer = 0.0f;
			}
			break;
		case EState_LoadingIn:
			UpdateLoadIn(frameTime);
			break;

		case EState_Bursting:
			UpdateBurst(frameTime);
			break;
	}
}
Exemplo n.º 2
0
//updates the world one tick
void UpdateGame(void)
{
   int numbigasteroids = 0, nummedasteroids = 0;
   LIST * cur;
   LIST * next;
   static unsigned int fpsframes = 0;
   static unsigned int last_fps_time = 0;
   unsigned int t;
   char hiscore_name[HS_NAME_LENGTH];

   if(g_paused)
      return;

   UpdateStarfield(&g_starfield);

   for(cur = g_asteroid_list; cur; cur = cur->next)
   {
      if(((ASTEROID *)cur->d)->scale == 4.0f)
         numbigasteroids++;
      else if(((ASTEROID *)cur->d)->scale == 2.0f)
         nummedasteroids++;
   }

   t = 1500*numbigasteroids + 500*nummedasteroids + (int)(16384.0/pow((double)g_score, 0.3010299956639811952));
   if(g_ships
      && !g_time_to_reset
      && g_level > 2
      && !(rand() % t))
   {
      NewAlien(g_score >= 10000 ? (rand() % 3) : 1);
   }

   t = (g_ships + 1) * 1000;
   if(g_ships
      && g_ships < 11
      && !g_time_to_reset
      && !(rand() % t))
   {
      NewPowerup();
   }

   for(cur = g_asteroid_list; cur; cur = cur->next)
      UpdateAsteroid(cur->d);

   if(g_ships)
      UpdatePlayer(&g_player, g_keys);

   for(cur = g_alien_list; cur; cur = next)
   {
      next = cur->next;

      UpdateAlien(cur->d, (g_ships ? &g_player : NULL), g_asteroid_list);
      if(((ALIEN *)cur->d)->pos.x < 0.0f || ((ALIEN *)cur->d)->pos.x > 40.0f)
         RemoveNode(cur, &g_alien_list);
   }

   for(cur = g_shot_list; cur; cur = next)
   {
      next = cur->next;

      UpdateShot(cur->d);
      if(!(((SHOT *)cur->d)->life))
         RemoveNode(cur, &g_shot_list);
   }

   for(cur = g_explosion_list; cur; cur = next)
   {
      next = cur->next;

      UpdateExplosion(cur->d);
      if(!(((EXPLOSION *)cur->d)->life))
         RemoveNode(cur, &g_explosion_list);
   }

   for(cur = g_burst_list; cur; cur = next)
   {
      next = cur->next;

      UpdateBurst(cur->d);
      if(!(((BURST *)cur->d)->life))
         RemoveNode(cur, &g_burst_list);
   }

   for(cur = g_powerup_list; cur; cur = next)
   {
      next = cur->next;

      UpdatePowerup(cur->d);
      if(((POWERUP *)cur->d)->pos.x < 0.0f || ((POWERUP *)cur->d)->pos.x > 40.0f)
         RemoveNode(cur, &g_powerup_list);
   }

   Clipping();

   g_frame++; //next frame
   if(g_time_to_reset && !(--g_time_to_reset))
      NextLevel();

   if(!g_ships && g_hisct_delay && !(--g_hisct_delay) && IsScoreHi(&g_hisct, g_score) && GetHiScoreName(hiscore_name))
      AddHiScore(&g_hisct, hiscore_name, g_score, g_level);

   fpsframes++;
   t = glutGet(GLUT_ELAPSED_TIME);
   if(t >= last_fps_time + 1000)
   {
      g_fps = (float)fpsframes / (float)(t - last_fps_time) * 1000.0f;
      fpsframes = 0;
      last_fps_time = t;
   }

   glutPostRedisplay();
}
Exemplo n.º 3
0
//------------------------------------------------------------------------
void CGunTurret::ServerUpdate(SEntityUpdateContext &ctx, int update)
{
	//update parameters. SNH: cache these in MP since they never change.
	if(!gEnv->bMultiplayer)
	{
		UpdateEntityProperties();
	}

	IEntity *pCurrentTarget = gEnv->pEntitySystem->GetEntity(m_targetId);
	IActor  *pCurrentActor = GetActor(m_targetId);

	bool mg=false;
	bool rocket=false;

	if(IsOperational())
	{
		bool renew_target = false;

		//do this before, cause it's more important
		if(m_turretparams.TAC_check_time != 0.f)
		{
			if(m_checkTACTimer>m_turretparams.TAC_check_time)
			{
				m_checkTACTimer = 0.0f;
				IEntity *pClosest = GetClosestTACShell();

				if(pClosest)
				{
					ChangeTargetTo(pClosest);
					pCurrentTarget = pClosest;
				}
			}
			else
				m_checkTACTimer += ctx.fFrameTime;
		}

		//actually if(...), break at end
		while(pCurrentTarget)
		{
			if(InternalIsFiring(false))
				m_burstTimer += ctx.fFrameTime;
			else
				m_burstTimer = 0.f;

			ETargetClass t_class = GetTargetClass(pCurrentTarget);
			bool validClass = (t_class!=eTC_NotATarget);

			Vec3 tpos = PredictTargetPos(pCurrentTarget,false);
			bool inrange = IsInRange(tpos, t_class);

			if(m_rayTimer <= 0.f)
			{
				m_canShoot = IsTargetShootable(pCurrentTarget);
				m_rayTimer = (m_canShoot) ? 0.5f : 0.2f;
			}
			else
				m_rayTimer -= ctx.fFrameTime;

			if(!(validClass && inrange && m_canShoot))
			{
				m_abandonTargetTimer += ctx.fFrameTime;
			}
			else
				m_abandonTargetTimer = 0.0f;

			if(m_abandonTargetTimer > m_turretparams.abandon_target_time + m_randoms[eRV_AbandonTarget].val)
			{
				renew_target = true;
				m_randoms[eRV_AbandonTarget].New();
				break;
			}

			bool aim = inrange&&m_canShoot&&IsAiming(tpos, m_turretparams.aim_tolerance);
			mg = aim && !m_turretparams.search_only && IsTargetMGable(tpos);

			bool burst = (m_turretparams.burst_time == 0.f || UpdateBurst(ctx.fFrameTime));
			mg &= burst;

			// a bit less tolerant for rockets
			aim=aim&&IsAiming(tpos, m_turretparams.aim_tolerance*0.5f);

			rocket = aim && !m_turretparams.search_only && m_fm2 && t_class == eTC_Vehicle && IsTargetRocketable(tpos);

			if(g_pGameCVars->i_debug_turrets)
			{
				IRenderer *pRenderer = gEnv->pRenderer;
				static float white[4] = {1,1,1,1};
				float x = 5.f, y = 50.f, step1 = 15.f, /*step2 = 20.f, */size=1.3f;

				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "Target: %s", pCurrentTarget->GetName());
				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "InRange: %i", inrange);
				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "CanShoot: %i", m_canShoot);
				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "IsAiming: %i", aim);
				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "Burst: %i", burst);
				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "MG: %i", mg);
				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "BurstTimer: %.2f", m_burstTimer);
				//pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "Rocket: %i", rocket);
				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "TargetPos: %.1f %.1f %.1f", tpos.x, tpos.y, tpos.z);
				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "Abandon: %.2f", m_abandonTargetTimer);
				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "Update: %.2f", m_updateTargetTimer);
				pRenderer->Draw2dLabel(x, y+=step1, size, white, false, "GoalYaw: %.2f, GoalPitch: %.2f", m_goalYaw, m_goalPitch);
			}

			break;
		}

		m_updateTargetTimer += ctx.fFrameTime;

		if(renew_target || m_updateTargetTimer > m_turretparams.update_target_time+m_randoms[eRV_UpdateTarget].Val())
		{
			IEntity *pClosestTAC = GetClosestTACShell();
			IEntity *pClosest = (pClosestTAC) ? pClosestTAC : GetClosestTarget();

			// change target if tac shell, or other target closer than current
			// otherwise, only change after abandoning time is exceeded
			if(pClosestTAC || (pClosest && pClosest->GetId()!=m_targetId) || (!pClosest && !(m_abandonTargetTimer>0.f && m_abandonTargetTimer<=m_turretparams.abandon_target_time)))
			{
				ChangeTargetTo(pClosest);
				pCurrentTarget = pClosest;
			}

			m_updateTargetTimer = 0.f;
			m_randoms[eRV_UpdateTarget].New();
		}

		if(pCurrentTarget)
		{
			if(m_turretparams.surveillance || IsTargetShootable(pCurrentTarget))
				UpdateGoal(pCurrentTarget, ctx.fFrameTime);
		}
		else
		{
			if(m_turretparams.searching)
			{
				UpdateSearchingGoal(ctx.fFrameTime);
			}
		}
	}

	if(m_fm && mg != InternalIsFiring(false))
	{
		if(mg)
			InternalStartFire(false);
		else
			InternalStopFire(false);
	}

	if(m_fm2 && rocket != InternalIsFiring(true))
	{
		if(rocket)
			InternalStartFire(true);
		else
			InternalStopFire(true);
	}
}