Пример #1
0
void Imp::step(bool hasSound)
{
	if (this->hasJob())
	{
		this->hasSound = hasSound;

		switch (this->job->type)
		{
			case MINE_TARGET:
			{
				if (!job->target->getBeingExtracted())
				{
					this->cancelJob();
				}
				else if (!this->job->destinationReached)
				{
					int milli = this->renegotiateTimer->getElapsedTime().asMilliseconds();

					if (milli > Imp::RENEGOTIATE_COOLDOWN)
					{
						this->renegotiate();
						this->renegotiateTimer->restart();
					}

					if (this->hasJob())
					{
						milli = this->moveTimer->getElapsedTime().asMilliseconds();

						if (milli > Imp::MOVE_COOLDOWN)
						{
							this->move();
							this->moveTimer->restart();
						}
					}
				}
				else if (!this->job->targetMined)
				{
					int milli = this->mineTimer->getElapsedTime().asMilliseconds();

					if (milli > Imp::MINE_COOLDOWN)
					{
						this->mine(job->target);
						this->mineTimer->restart();
					}
				}
				else
					this->completeJob();

				break;
			}

			case UNLOAD_GOLD:
			{
				if (job->destination->hasMaxGold())
				{
					this->cancelJob();
				}
				else if (!this->job->destinationReached)
				{
					int milli = this->renegotiateTimer->getElapsedTime().asMilliseconds();

					if (milli > Imp::RENEGOTIATE_COOLDOWN)
					{
						this->renegotiate();
						this->renegotiateTimer->restart();
					}

					if (this->hasJob())
					{
						milli = this->moveTimer->getElapsedTime().asMilliseconds();

						if (milli > Imp::MOVE_COOLDOWN)
						{
							this->move();
							this->moveTimer->restart();
						}
					}
				}
				else
				{
					if (this->hasSound)
					{
						int random = rand() % 3 + 1;
						string name = "gold_drop_" + to_string(random);
						SoundHandler::playCriticalSound(name);
					}

					this->job->goldDropped = true;

					Tile* destination = this->job->destination;

					int depositableGold = destination->getStoreableGold();

					if (currentGold < depositableGold)
						depositableGold = currentGold;

					this->currentGold -= depositableGold;

					destination->addGold(depositableGold);

					this->completeJob();
				}

				break;

			}

			case MOVE_ORDER:
			{
				break;
			}

			default:
				break;
		}
	}
}