Ejemplo n.º 1
0
void TimeControl::update()
{
	m_lastMoveTime = m_time.elapsed();

	if (!m_infinite && m_lastMoveTime > m_timeLeft + m_expiryMargin)
		m_expired = true;

	if (m_timePerMove != 0)
		setTimeLeft(m_timePerMove);
	else
	{
		setTimeLeft(m_timeLeft + m_increment - m_lastMoveTime);
		
		if (m_movesPerTc > 0)
		{
			setMovesLeft(m_movesLeft - 1);
			
			// Restart the time control
			if (m_movesLeft == 0)
			{
				setMovesLeft(m_movesPerTc);
				setTimeLeft(m_timePerTc + m_timeLeft);
			}
		}
	}
}
Ejemplo n.º 2
0
void TimeControl::update()
{
	/*
	 * This will overflow after roughly 49 days however it's unlikely
	 * we'll ever hit that limit.
	 */
	m_lastMoveTime = (int)m_time.elapsed();

	if (!m_infinite && m_lastMoveTime > m_timeLeft + m_expiryMargin)
		m_expired = true;

	if (m_timePerMove != 0)
		setTimeLeft(m_timePerMove);
	else
	{
		setTimeLeft(m_timeLeft + m_increment - m_lastMoveTime);
		
		if (m_movesPerTc > 0)
		{
			setMovesLeft(m_movesLeft - 1);
			
			// Restart the time control
			if (m_movesLeft == 0)
			{
				setMovesLeft(m_movesPerTc);
				setTimeLeft(m_timePerTc + m_timeLeft);
			}
		}
	}
}
Ejemplo n.º 3
0
void GameScene::restart() {
    setScore(0);
    setTimeLeft(kGameSessionTime);

    _field->shuffle();
    _restartLabel->setHidden(true);

    _gameOver = false;
}
Ejemplo n.º 4
0
void GameScene::gameOver() {
    setTimeLeft(0);

    _gameOver = true;

    _restartLabel->setHidden(false);

    SoundManager::mngr()->playEffect("lvlComplete.wav");
}
Ejemplo n.º 5
0
/** Updates the attachments in case of a kart-kart collision. This must only
 *  be called for one of the karts in the collision, since it will update
 *  the attachment for both karts.
 *  \param other Pointer to the other kart hit.
 */
void Attachment::handleCollisionWithKart(AbstractKart *other)
{
    Attachment *attachment_other=other->getAttachment();
    
    if(getType()==Attachment::ATTACH_BOMB)
    {
        // Don't attach a bomb when the kart is shielded
        if(other->isShielded())
        {
            other->decreaseShieldTime();
            return;
        }
        // If both karts have a bomb, explode them immediately:
        if(attachment_other->getType()==Attachment::ATTACH_BOMB)
        {
            setTimeLeft(0.0f);
            attachment_other->setTimeLeft(0.0f);
        }
        else  // only this kart has a bomb, move it to the other
        {
            // if there are only two karts, let them switch bomb from one to other
            if (getPreviousOwner() != other || World::getWorld()->getNumKarts() <= 2)
            {
                // Don't move if this bomb was from other kart originally
                other->getAttachment()->set(ATTACH_BOMB,
                                            getTimeLeft()+
                                            stk_config->m_bomb_time_increase,
                                            m_kart);
                other->playCustomSFX(SFXManager::CUSTOM_ATTACH);
                clear();
            }
        }
    }   // type==BOMB
    else if(attachment_other->getType()==Attachment::ATTACH_BOMB &&
            (attachment_other->getPreviousOwner()!=m_kart || World::getWorld()->getNumKarts() <= 2))
    {
        // Don't attach a bomb when the kart is shielded
        if(m_kart->isShielded())
        {
            m_kart->decreaseShieldTime();
            return;
        }
        set(ATTACH_BOMB, other->getAttachment()->getTimeLeft()+
                         stk_config->m_bomb_time_increase, other);
        other->getAttachment()->clear();
        m_kart->playCustomSFX(SFXManager::CUSTOM_ATTACH);
    }
    else
    {
        m_kart->playCustomSFX(SFXManager::CUSTOM_CRASH);
        other->playCustomSFX(SFXManager::CUSTOM_CRASH);
    }

}   // handleCollisionWithKart
Ejemplo n.º 6
0
	void TransferApi::onTransferCompleted(const Transfer* aTransfer, bool aIsDownload) noexcept {
		auto t = getTransfer(aTransfer->getToken());
		if (!t) {
			return;
		}

		t->setStatusString("Finished, idle...");
		t->setSpeed(-1);
		t->setTimeLeft(-1);
		t->setBytesTransferred(aTransfer->getSegmentSize());
		t->setState(TransferInfo::STATE_FINISHED);

		view.onItemUpdated(t, { 
			TransferUtils::PROP_STATUS, TransferUtils::PROP_SPEED,
			TransferUtils::PROP_SECONDS_LEFT, TransferUtils::PROP_TIME_STARTED,
			TransferUtils::PROP_BYTES_TRANSFERRED
		});
	}
Ejemplo n.º 7
0
/** Updates the attachments in case of a kart-kart collision. This must only
 *  be called for one of the karts in the collision, since it will update
 *  the attachment for both karts.
 *  \param other Pointer to the other kart hit.
 */
void Attachment::handleCollisionWithKart(AbstractKart *other)
{
    Attachment *attachment_other=other->getAttachment();

    if(getType()==Attachment::ATTACH_BOMB)
    {
        // If both karts have a bomb, explode them immediately:
        if(attachment_other->getType()==Attachment::ATTACH_BOMB)
        {
            setTimeLeft(0.0f);
            attachment_other->setTimeLeft(0.0f);
        }
        else  // only this kart has a bomb, move it to the other
        {
            if(getPreviousOwner()!=other)
            {
                // Don't move if this bomb was from other kart originally
                other->getAttachment()->set(ATTACH_BOMB,
                                            getTimeLeft()+
                                            stk_config->m_bomb_time_increase,
                                            m_kart);
                other->playCustomSFX(SFXManager::CUSTOM_ATTACH);
                clear();
            }
        }
    }   // type==BOMB
    else if(attachment_other->getType()==Attachment::ATTACH_BOMB &&
            attachment_other->getPreviousOwner()!=m_kart)
    {
        set(ATTACH_BOMB, other->getAttachment()->getTimeLeft()+
                         stk_config->m_bomb_time_increase, other);
        other->getAttachment()->clear();
        m_kart->playCustomSFX(SFXManager::CUSTOM_ATTACH);
    }
    else
    {
        m_kart->playCustomSFX(SFXManager::CUSTOM_CRASH);
        other->playCustomSFX(SFXManager::CUSTOM_CRASH);
    }

}   // handleCollisionWithKart
Ejemplo n.º 8
0
	void TransferApi::onTick(const Transfer* aTransfer, bool aIsDownload) noexcept {
		auto t = getTransfer(aTransfer->getToken());
		if (!t) {
			return;
		}

		t->setSpeed(aTransfer->getAverageSpeed());
		t->setBytesTransferred(aTransfer->getPos());
		t->setTimeLeft(aTransfer->getSecondsLeft());

		uint64_t timeSinceStarted = GET_TICK() - t->getStarted();
		if (timeSinceStarted < 1000) {
			t->setStatusString("Starting...");
		} else {
			t->setStatusString(STRING_F(RUNNING_PCT, t->getPercentage()));
		}

		view.onItemUpdated(t, { 
			TransferUtils::PROP_STATUS, TransferUtils::PROP_BYTES_TRANSFERRED, 
			TransferUtils::PROP_SPEED, TransferUtils::PROP_SECONDS_LEFT
		});
	}
Ejemplo n.º 9
0
//Gets the next page id and page think time    
static int getNextPageAndThinkTime(char *curPageName, int curPageId, double *pg_think_time_out)
{
  int nextPageId;
  unsigned int pg_think_time;
  int curServiceId = ns_get_int_val("ServiceIdVar"); 

  unsigned long curTS = ns_get_ms_stamp();
  
  set_kiosk_id_for_debug(); // This will set KioskId once for debug log
  strcpy(KioskId, ns_eval_string("{KioskIdVar}"));

  setTimeLeft(RB_KIOSK_PING_ID, curTS, getLastPingTS(), KioskPing, -1);
  setTimeLeft(RB_RENT_SERVICE_ID, curTS, getLastRentalTS(), RentService, ReconcileService);
  setTimeLeft(RB_RETURN_SERVICE_ID, curTS, getLastReturnTS(), ReturnService, -1);
  setTimeLeft(RB_FAILURE_RENT_SERVICE_ID, curTS, getLastFailureRentalTS(), AuthorizeFailure, ReconcileFailure);
  setTimeLeft(RB_OFFLINE_RENT_SERVICE_ID, curTS, getLastOfflineRentalTS(), ReconcileService, -1);

#ifdef RB_ENABLE_NEW_SVC
  setTimeLeft(RB_UNPLAYABLE_ID, curTS, getLastUnplayableTS(), UnplayableReturnService, ReturnService2);
  setTimeLeft(RB_KIOSK_ANALYTICS_ID, curTS, getLastKioskAnalyticsTS(), KioskAnalytics, -1);
  setTimeLeft(RB_DISCOUNT_VALIDATION_ID, curTS, getLastDiscountValidationTS(), DiscountValidationService, RentService);
  setTimeLeft(RB_GETCUST_CREDIT_ID, curTS, getLastGetCustCreditTS(), GetCustCredit, RentService);
  setTimeLeft(RB_RENT_OPTIN_ID, curTS, getLastOptInRentalTS(), RentService, KioskOptInService);
  setTimeLeft(RB_DISC_ACTION_ID, curTS, getLastDiscActionTS(), DiscActionService, -1);
  setTimeLeft(RB_EMAIL_CONFIRM_ID, curTS, getLastEmailConfirmTS(), EmailConfirmation, -1);
  setTimeLeft(RB_PICK_UP_ID, curTS, getLastPickUpValidationTS(), PickUpValidation, PickUp);
  setTimeLeft(RB_GIFTCARD_ID, curTS, getLastGCRentalTS(), RentService, ReconcileService);
  setTimeLeft(RB_GC_PICKUP_ID, curTS, getLastGCPickUpValidationTS(), PickUpValidation, PickUp);
#endif

  int curPageStatus = ns_get_page_status(); // 0 - Success else fail
  if(curPageStatus != 0) 
  {
    #ifdef NS_DEBUG_ON
    fprintf(stderr, "%s - Warning: %s page failed. KioskId = %s\n", tsToStr(curTS),curPageName, KioskId);
    #endif
    curPageId = -1; // Set to -1 so avoid going to Reconcile after ping
  }
 
  // TODO: Can we elimiate this?
  if((curPageId == GetCustCredit) && (curPageStatus == 0))
  {
    nextPageId = RentService;
    pg_think_time = getTTForNextPgOfAService(curTS, getThinkTimeForRent(), &nextPageId, "GetCustCredit");
  }
  else if((curPageId == DiscountValidationService) && (curPageStatus == 0))
  {
    nextPageId = RentService;
    pg_think_time = getTTForNextPgOfAService(curTS, getThinkTimeForRent(), &nextPageId, "DiscountValidationService");
  }
  // if current page is RentService, next page can be Reconcile or OptIn
  else if((curPageId == RentService) && (curPageStatus == 0) && (curServiceId == RB_RENT_OPTIN_ID))
  {
   nextPageId = KioskOptInService;
   pg_think_time = getTTForNextPgOfAService(curTS, getThinkTimeForOptIn(), &nextPageId, "RentService");
   }
  else if((curPageId == RentService) && (curPageStatus == 0) && (curServiceId != RB_RENT_OPTIN_ID))
   {
    nextPageId = ReconcileService;
    pg_think_time = getTTForNextPgOfAService(curTS, getThinkTimeForReconcile(), &nextPageId, "RentService");
   }
  else if((curPageId == KioskOptInService) && (curPageStatus == 0) && (curServiceId == RB_RENT_OPTIN_ID))
  {
    nextPageId = ReconcileService;
    pg_think_time = getTTForNextPgOfAService(curTS, getThinkTimeForReconcile(), &nextPageId, "KioskOptInService");
  }
  // If current page is UnplayableReturnService then next can either be ReturnService2 or Ping
  else if ((curPageId == AuthorizeFailure) && (curPageStatus == 0))
  {
    nextPageId = ReconcileFailure;
    pg_think_time = getTTForNextPgOfAService(curTS, getThinkTimeForReconcile(), &nextPageId, "AuthorizeFailure");
  }
  else if ((curPageId == UnplayableReturnService) && (curPageStatus == 0))
  {
    nextPageId = ReturnService2;
    pg_think_time = getTTForNextPgOfAService(curTS, getThinkTimeForReturnService2(), &nextPageId, "UnplayableReturnService");
  }
  else if ((curPageId == PickUpValidation) && (curPageStatus == 0))
  {
    nextPageId = PickUp;
    pg_think_time = getTTForNextPgOfAService(curTS, getThinkTimeForPickUp(), &nextPageId, "PickUpValidation");
  }
  else if(curPageId == KioskPing) 
  // Check if due to ping, we did not do ReconcileService last time
  { 
    if((getPageIdBeforePing() == GetCustCredit) && (getServiceIdBeforePing() == RB_GETCUST_CREDIT_ID))
    {
      pg_think_time = ns_get_int_val("PgThinkTimeVar");
      nextPageId = RentService;
    }
    else if((getPageIdBeforePing() == DiscountValidationService) && (getServiceIdBeforePing() == RB_DISCOUNT_VALIDATION_ID))
    {
      pg_think_time = ns_get_int_val("PgThinkTimeVar");
      nextPageId = RentService;
    }
    else if((getPageIdBeforePing() == RentService) && (getServiceIdBeforePing() != RB_RENT_OPTIN_ID))
    {
      pg_think_time = ns_get_int_val("PgThinkTimeVar");
      nextPageId = ReconcileService;
    }
    else if((getPageIdBeforePing() == RentService) && (getServiceIdBeforePing() == RB_RENT_OPTIN_ID))
    {
      pg_think_time = ns_get_int_val("PgThinkTimeVar");
      nextPageId = KioskOptInService;
    }
    else if((getPageIdBeforePing() == KioskOptInService) && (getServiceIdBeforePing() == RB_RENT_OPTIN_ID))
    {
      pg_think_time = ns_get_int_val("PgThinkTimeVar");
      nextPageId = ReconcileService;
    }
    else if((getPageIdBeforePing() == UnplayableReturnService) && (getServiceIdBeforePing() == RB_UNPLAYABLE_ID))
    {
      pg_think_time = ns_get_int_val("PgThinkTimeVar");
      nextPageId = ReturnService2;
    }
    else if((getPageIdBeforePing() == AuthorizeFailure) && (getServiceIdBeforePing() == RB_FAILURE_RENT_SERVICE_ID))
    {
      pg_think_time = ns_get_int_val("PgThinkTimeVar");
      nextPageId = ReconcileFailure;
    }
    else if((getPageIdBeforePing() == PickUpValidation) && ((getServiceIdBeforePing() == RB_PICK_UP_ID) || (getServiceIdBeforePing() == RB_GC_PICKUP_ID)))
    {
      pg_think_time = ns_get_int_val("PgThinkTimeVar");
      nextPageId = PickUp;
    }
    else
      pg_think_time = selectService(curTS, &nextPageId); 
  }
  else 
  {  
    pg_think_time = selectService(curTS, &nextPageId); 
  }


  if(nextPageId == KioskPing)
  {
    setPageIdBeforePing(curPageId);
    setServiceIdBeforePing(curServiceId);
  }
  // ns_set_pg_think_time(pg_think_time);
  *pg_think_time_out = (double )pg_think_time/1000.0; // page think time in C Type is passed in seconds

   #ifdef NS_DEBUG_ON
if(isKioskSetForDebug())
 fprintf(stderr, "%s - Info: getNextPageAndThinkTime() - KioskId = %s , pg_think_time = %u, nextPageId = %d\n",  tsToStr(curTS), KioskId, pg_think_time, nextPageId);
#endif  
return(nextPageId);
}
Ejemplo n.º 10
0
void GameScene::tick(Float dt) {
    _timeLeft -= dt;

    setTimeLeft(_timeLeft);
}
Ejemplo n.º 11
0
Timer::Timer(int timeLeft):
	endTime_(0)
{
	setTimeLeft(timeLeft);
}