text: #include <algorithm>
  #include <cmath>
  #include <string>
  
  #include "gameplay/GameBoard.h"
  #include "gameplay/PlayScreen.h"
  #include "gameplay/PlayScreenMarathon.h"
  
  #include "gameplay/GameBoardMarathon.h"
  
  using namespace std::string_literals;
  
  #define ownerMarathon static_cast<PlayScreenMarathon*>(owner)
  
  GameBoardMarathon::GameBoardMarathon(PlayScreen *const owner):
  	GameBoard(owner)
  {
  	animateClearOnFinish = false;
  }
  
  void GameBoardMarathon::lock() {
  	long oldLines = lines;
  	GameBoard::lock();
  	if (oldLines != lines) ownerMarathon->onLineClear(oldLines, lines);
  	if (owner->gameState != FINISHED || lost)
  		spawnLineClearParticles(0.5, 200, 500);
  }
  
  void GameBoardMarathon::processRewardAmount(long &rewardAmount) {
  	rewardAmount *= std::min(149l, lines)/10 + 1;
  }
  
  float GameBoardMarathon::getFallPeriod() {
  	const int level = std::min(149l, lines)/10 + 1;
  	return std::pow(0.8 - level*0.007, level)*1000;
  }
  
  long GameBoardMarathon::getLockDelay() {
  	return 500;
  }
  
  void GameBoardMarathon::gameOver() {
  	GameBoard::gameOver();
  	owner->gameOver();
  }
  
  void GameBoardMarathon::renderOtherObjects(const long timePassed) {
  	const Color textColor = {1, 1, 1, 1}, textOutline = {0, 0, 0, 1};
  	owner->commonResources.font.render(
  		"LEVEL"s, -1, 3.8, 0, 0.9, 1, true, 0, 1, 0, false, 0,
  		 textColor, textOutline
  	);
  	owner->commonResources.font.render(
  		std::to_string(std::min(149l, lines)/10 + 1),
  		-1, 2.6, 0, 1.25, 1, true, 0, 1, 0, false, 0,
  		textColor, textOutline
  	);
  	owner->commonResources.font.render(
  		"LINES"s, -1, 1.3, 0, 0.9, 1, true, 0, 1, 0, false, 0,
  		 textColor, textOutline
  	);
  	const float goalWidth = owner->commonResources.font.render(
  		" / 150"s,
  		-1, 0.1, 0, 0.9, 1, true, 0, 1, 0, false, 0,
  		textColor, textOutline
  	);
  	owner->commonResources.font.render(
  		std::to_string(lines),
  		-1-goalWidth, 0.1, 0, 1.25, 1, true, 0, 1, 0, false, 0,
  		textColor, textOutline
  	);
  	
  	owner->commonResources.font.render(
  		"TIME"s, 11, 3.8, 0, 0.9, 0, true, 0, 1, 0, false, 0,
  		 textColor, textOutline
  	);
  	owner->commonResources.font.render(
  		Utils::formatDuration(
  			owner->commonResources.settings, owner->gameTime
  		),
  		11, 2.6, 0, 1.25, 0, true, 0, 1, 0, false, 0,
  		textColor, textOutline
  	);
  	owner->commonResources.font.render(
  		"SCORE"s, 11, 1.3, 0, 0.9, 0, true, 0, 1, 0, false, 0,
  		textColor, textOutline
  	);
  	owner->commonResources.font.render(
  		Utils::formatInteger(owner->commonResources.settings, score),
  		11, 0.1, 0, 1.25, 0, true, 0, 1, 0, false, 0,
  		textColor, textOutline
  	);
  
  	if (
  		owner->gameState == WARMUP &&
  		owner->sceneTime < 3151 && owner->sceneTime > 150
  	) {
  		const long millis = owner->sceneTime % 1000;
  		owner->commonResources.font.render(
  			std::to_string((owner->sceneTime - 151) / 1000),
  			5, 14, 0, 3.5, 0.5, true, 0,
  			millis > 150 ? 1 : 1 + millis/300.f, 0.5, false, 0.5,
  			{
  				1, 1, 1, 
  				millis > 500 ? 1 :
  				millis > 150 ? (millis - 150) / 350.f :
  				(150 - millis) / 150.f
  			}
  		);
  	}
  }
  
  #undef ownerMarathon