<commit_before><?php
require_once("module.php");
require_once("media.php");
require_once("quests.php");

class Games extends Module
{	
	
	/**
     * Fetch all games
     * @returns Object Recordset for each Game.
     */
	public function getGames()
	{
	    $query = "SELECT * FROM games";
		$rs = @mysql_query($query);
		if (mysql_error())  return new returnData(3, NULL, 'SQL error');
		return new returnData(0, $rs, NULL);		
	}

	/**
     * Fetch one game
     * @returns Object Recordset for each Game.
     */
	public function getGame($intGameID)
	{
	    $query = "SELECT * FROM games WHERE game_id = {$intGameID} LIMIT 1";
		$rs = @mysql_query($query);
		if (mysql_error())  return new returnData(3, NULL, 'SQL error');

		$game = @mysql_fetch_object($rs);
		if (!$game) return new returnData(2, NULL, "invalid game id");
		
		return new returnData(0, $game);

	}


	/**
     * Fetch all games with distences from the current location - DEPRICATED
     * @returns Object Recordset for each Game.
     */
	public function getGamesWithDetails($player_id=NULL, $latitude=NULL, $longitude=NULL)
	{
	    $query = "SELECT games.* 
	    			FROM games";
	    				    	
		$gamesRs = @mysql_query($query);
		NetDebug::trace(mysql_error());

		$games = array();
		
		
		while ($game = @mysql_fetch_object($gamesRs)) {
			//Calculate the nearest Location
	    	if ($player_id != NULL) {
				//Calculate the game distances from the player position
				$query = "SELECT latitude, longitude,((ACOS(SIN($latitude * PI() / 180) * SIN(latitude * PI() / 180) + 
						COS($latitude * PI() / 180) * COS(latitude * PI() / 180) * 
						COS(($longitude - longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) * 1609.344
					AS `distance`
					FROM {$game->game_id}_locations
					WHERE type != 'Item' OR item_qty > 0
					ORDER BY distance ASC";
				//NetDebug::trace($query);	
				$nearestLocationRs = @mysql_query($query);
				NetDebug::trace(mysql_error());	
				$nearestLocation = @mysql_fetch_object($nearestLocationRs);
				$game->distance = $nearestLocation->distance;
				$game->latitude = $nearestLocation->latitude;
				$game->longitude = $nearestLocation->longitude;
				
				//Calculate the quest info
				$questsReturnData = Quests::getQuestsForPlayer($game->game_id,$player_id);
				$game->totalQuests = $questsReturnData->data->totalQuests;
				$game->completedQuests = count($questsReturnData->data->completed);
			}
			else {
				//Calculate the centroid of the locations for this game
				$query = "SELECT * 
						FROM {$game->prefix}locations";
				$locationsRs = @mysql_query($query);
				NetDebug::trace(mysql_error());
	
				$latAve = 0;
				$longAve = 0;
				$latTotal = 0;
				$longTotal = 0;<commit_msg>Force media_id and icon_id = 0 for client that is not ready to accept anything else<commit_after><?php
require_once("module.php");
require_once("media.php");
require_once("quests.php");

class Games extends Module
{	
	
	/**
     * Fetch all games
     * @returns Object Recordset for each Game.
     */
	public function getGames()
	{
	    $query = "SELECT * FROM games";
		$rs = @mysql_query($query);
		if (mysql_error())  return new returnData(3, NULL, 'SQL error');
		return new returnData(0, $rs, NULL);		
	}

	/**
     * Fetch one game
     * @returns Object Recordset for each Game.
     */
	public function getGame($intGameID)
	{
	    $query = "SELECT * FROM games WHERE game_id = {$intGameID} LIMIT 1";
		$rs = @mysql_query($query);
		if (mysql_error())  return new returnData(3, NULL, 'SQL error');

		$game = @mysql_fetch_object($rs);
		if (!$game) return new returnData(2, NULL, "invalid game id");
		
		return new returnData(0, $game);

	}


	/**
     * Fetch all games with distences from the current location - DEPRICATED
     * @returns Object Recordset for each Game.
     */
	public function getGamesWithDetails($player_id=NULL, $latitude=NULL, $longitude=NULL)
	{
	    $query = "SELECT games.* 
	    			FROM games";
	    				    	
		$gamesRs = @mysql_query($query);
		NetDebug::trace(mysql_error());

		$games = array();
		
		
		while ($game = @mysql_fetch_object($gamesRs)) {
			//Calculate the nearest Location
	    	if ($player_id != NULL) {
				//Calculate the game distances from the player position
				$query = "SELECT latitude, longitude,((ACOS(SIN($latitude * PI() / 180) * SIN(latitude * PI() / 180) + 
						COS($latitude * PI() / 180) * COS(latitude * PI() / 180) * 
						COS(($longitude - longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) * 1609.344
					AS `distance`
					FROM {$game->game_id}_locations
					WHERE type != 'Item' OR item_qty > 0
					ORDER BY distance ASC";
				//NetDebug::trace($query);	
				$nearestLocationRs = @mysql_query($query);
				NetDebug::trace(mysql_error());	
				$nearestLocation = @mysql_fetch_object($nearestLocationRs);
				$game->distance = $nearestLocation->distance;
				$game->latitude = $nearestLocation->latitude;
				$game->longitude = $nearestLocation->longitude;
				$game->icon_media_id = 0;
				$game->media_id = 0;
				
				//Calculate the quest info
				$questsReturnData = Quests::getQuestsForPlayer($game->game_id,$player_id);
				$game->totalQuests = $questsReturnData->data->totalQuests;
				$game->completedQuests = count($questsReturnData->data->completed);
			}
			else {
				//Calculate the centroid of the locations for this game
				$query = "SELECT * 
						FROM {$game->prefix}locations";
				$locationsRs = @mysql_query($query);
				NetDebug::trace(mysql_error());
	
				$latAve = 0;
				$longAve = 0;
				$latTotal = 0;
				$longTotal = 0;
{'fraction_non_alphanumeric': 0.14676751305600577, 'fraction_numerical': 0.01602737259139204, 'mean_word_length': 3.2921174652241114, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3842944', 'n_tokens_mistral': 2207, 'n_tokens_neox': 1798, 'n_words': 455}